Skip to content

Commit

Permalink
NXDRIVE-890: Cleanup Windows XP specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG authored Jul 4, 2017
1 parent 565cb09 commit fbfe879
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 128 deletions.
2 changes: 1 addition & 1 deletion nuxeo-drive-client/nxdrive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
- X.Y.ZbN i.e. "2.4.5b1"
"""

__version__ = '2.4.6'
__version__ = '2.4.7'
58 changes: 27 additions & 31 deletions nuxeo-drive-client/nxdrive/client/local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,46 +259,41 @@ def set_folder_icon(self, ref, icon):
self.set_folder_icon_darwin(ref, icon)

def set_folder_icon_win32(self, ref, icon):
""" Configure red color icon for a folder Windows / Mac. """
""" Configure red color icon for a folder Windows / macOS. """

# Desktop.ini file content for Windows 7 and later.
# Desktop.ini file content for Windows 7+.
ini_file_content = """
[.ShellClassInfo]
IconResource=icon_file_path,0
[ViewState]
Mode=
Vid=
FolderType=Generic
"""
# Desktop.ini file content for Windows XP.
ini_file_content_xp = """
[.ShellClassInfo]
IconFile=icon_file_path
IconIndex=0
"""
if AbstractOSIntegration.os_version_below("5.2"):
desktop_ini_content = ini_file_content_xp.replace("icon_file_path", icon)
else:
desktop_ini_content = ini_file_content.replace("icon_file_path", icon)
[.ShellClassInfo]
IconResource={icon},0
[ViewState]
Mode=
Vid=
FolderType=Generic
"""
desktop_ini_content = ini_file_content.format(icon=icon)

# Create the desktop.ini file inside the ReadOnly shared folder.
created_ini_file_path = os.path.join(self.abspath(ref), 'desktop.ini')
attrib_command_path = self.abspath(ref)
if not os.path.exists(created_ini_file_path):
try:
create_file = open(created_ini_file_path,'w')
create_file.write(desktop_ini_content)
create_file.close()
win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_SYSTEM)
win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_HIDDEN)
except Exception as e:
log.error("Exception when setting folder icon : %r", e)
with open(created_ini_file_path, 'w') as create_file:
create_file.write(desktop_ini_content)
win32api.SetFileAttributes(created_ini_file_path,
win32con.FILE_ATTRIBUTE_SYSTEM)
win32api.SetFileAttributes(created_ini_file_path,
win32con.FILE_ATTRIBUTE_HIDDEN)
except:
log.exception('Icon folder cannot be set')
else:
win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_SYSTEM)
win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_HIDDEN)
win32api.SetFileAttributes(created_ini_file_path,
win32con.FILE_ATTRIBUTE_SYSTEM)
win32api.SetFileAttributes(created_ini_file_path,
win32con.FILE_ATTRIBUTE_HIDDEN)
# Windows folder use READ_ONLY flag as a customization flag ...
# https://support.microsoft.com/en-us/kb/326549
win32api.SetFileAttributes(attrib_command_path, win32con.FILE_ATTRIBUTE_READONLY)
win32api.SetFileAttributes(attrib_command_path,
win32con.FILE_ATTRIBUTE_READONLY)

@staticmethod
def _read_data(file_path):
Expand All @@ -317,13 +312,14 @@ def _get_icon_xdata():
return result

def set_folder_icon_darwin(self, ref, icon):
''' Mac: Configure a folder with a given custom icon
"""
macOS: configure a folder with a given custom icon
1. Read the com.apple.ResourceFork extended attribute from the icon file
2. Set the com.apple.FinderInfo extended attribute with folder icon flag
3. Create a Icon file (name: Icon\r) inside the target folder
4. Set extended attributes com.apple.FinderInfo & com.apple.ResourceFork for icon file (name: Icon\r)
5. Hide the icon file (name: Icon\r)
'''
"""
try:
target_folder = self.abspath(ref)
# Generate the value for 'com.apple.FinderInfo'
Expand Down
4 changes: 1 addition & 3 deletions nuxeo-drive-client/nxdrive/engine/watcher/local_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,7 @@ def _setup_watchdog(self):
ob.read_directory_changes.WATCHDOG_TRAVERSE_MOVED_DIR_DELAY = 0
ob.winapi.BUFFER_SIZE = self._windows_watchdog_event_buffer
except ImportError:
log.trace('read_directory_changes import error', exc_info=True)
log.warn('Cannot import read_directory_changes, probably under'
' Windows XP, watchdog will fall back on polling')
log.warn('Cannot import read_directory_changes', exc_info=True)
log.debug('Watching FS modification on : %s', self.client.base_folder)

# Filter out all ignored suffixes. It will handle custom ones too.
Expand Down
4 changes: 0 additions & 4 deletions nuxeo-drive-client/nxdrive/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,6 @@ def get_default_nuxeo_drive_folder(self):
" falling back on manual detection of My Documents")
my_documents = os.path.expanduser(r'~\Documents')
my_documents = unicode(my_documents.decode(ENCODING))
if not os.path.exists(my_documents):
# Compatibility for Windows XP
my_documents = os.path.expanduser(r'~\My Documents')
my_documents = unicode(my_documents.decode(ENCODING))

if os.path.exists(my_documents):
nuxeo_drive_folder = self._increment_local_folder(my_documents, self._get_default_nuxeo_drive_name())
Expand Down
66 changes: 40 additions & 26 deletions nuxeo-drive-client/nxdrive/osi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ def __init__(self, manager):
def register_startup(self):
pass

def is_partition_supported(self, folder):
@staticmethod
def is_partition_supported(folder):
return True

def get_zoom_factor(self):
@staticmethod
def get_zoom_factor():
return 1.00

def uninstall(self):
Expand Down Expand Up @@ -132,7 +134,8 @@ def register_desktop_link(self):
def unregister_desktop_link(self):
pass

def is_same_partition(self, folder1, folder2):
@staticmethod
def is_same_partition(folder1, folder2):
return os.stat(folder1).st_dev == os.stat(folder2).st_dev

def get_system_configuration(self):
Expand Down Expand Up @@ -164,43 +167,54 @@ def get_os_version():
if AbstractOSIntegration.is_mac():
return platform.mac_ver()[0]
if AbstractOSIntegration.is_windows():
# 5.0.2195 Windows 2000
# 5.1.2600 Windows XP or Windows XP 64-Bit Edition Version 2002 (Itanium)
# 5.2.3790 Windows Server 2003 or Windows XP x64 Edition (AMD64/EM64T) or Windows XP 64-Bit Edition Version 2003 (Itanium)
# 6.0.6000 Windows Vista
# 6.0.6001 Windows Vista with Service Pack 1 or Windows Server 2008
# 6.1.7600 Windows 7 or Windows Server 2008 R2
# 6.1.7601 Windows 7 with Service Pack 1 or Windows Server 2008 R2 with Service Pack 1
# 6.2.9200 Windows 8 or Windows Server 2012
# 6.3.9200 Windows 8.1 or Windows Server 2012 R2
# 6.3.9600 Windows 8.1 with Update 1
# 6.4. Windows 10
"""
5.0.2195 Windows 2000
5.1.2600 Windows XP
Windows XP 64-Bit Edition Version 2002 (Itanium)
5.2.3790 Windows Server 2003
Windows XP x64 Edition (AMD64/EM64T)
Windows XP 64-Bit Edition Version 2003 (Itanium)
6.0.6000 Windows Vista
6.0.6001 Windows Vista SP1
Windows Server 2008
6.1.7600 Windows 7
Windows Server 2008 R2
6.1.7601 Windows 7 SP1
Windows Server 2008 R2 SP1
6.2.9200 Windows 8
Windows Server 2012
6.3.9200 Windows 8.1
Windows Server 2012 R2
6.3.9600 Windows 8.1 with Update 1
6.4. Windows 10
"""
return platform.win32_ver()[1]
else:
raise RuntimeError("Can't determine Linux versions")

raise RuntimeError('Cannot determine GNU/Linux version')

@staticmethod
def is_mac():
return sys.platform == "darwin"
return sys.platform == 'darwin'

@staticmethod
def is_windows():
return sys.platform == "win32"
return sys.platform == 'win32'

@staticmethod
def is_linux():
return not (AbstractOSIntegration.is_mac() or AbstractOSIntegration.is_windows())
return not (AbstractOSIntegration.is_mac()
or AbstractOSIntegration.is_windows())

@staticmethod
def get(manager):
if sys.platform == "darwin":
if AbstractOSIntegration.is_mac():
from nxdrive.osi.darwin.darwin import DarwinIntegration
log.debug("Using Darwin OS integration")
log.debug('Using macOS integration')
return DarwinIntegration(manager)
elif sys.platform == "win32":
elif AbstractOSIntegration.is_windows():
from nxdrive.osi.windows.windows import WindowsIntegration
log.debug("Using Windows OS integration")
log.debug('Using Windows OS integration')
return WindowsIntegration(manager)
else:
log.debug("Not using any OS integration")
return AbstractOSIntegration(manager)

log.debug('Not using any OS integration')
return AbstractOSIntegration(manager)
5 changes: 0 additions & 5 deletions nuxeo-drive-client/nxdrive/osi/darwin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
'''
Created on 11 aout 2015
@author: Remi Cattiau
'''
60 changes: 31 additions & 29 deletions nuxeo-drive-client/nxdrive/osi/darwin/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,20 @@ def macRightClick_userData_error_(self, pboard, data, error):


class DarwinIntegration(AbstractOSIntegration):
'''
classdocs
'''
NXDRIVE_SCHEME = 'nxdrive'
NDRIVE_AGENT_TEMPLATE = """\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.nuxeo.drive.agentlauncher</string>
<key>RunAtLoad</key>
<true/>
<key>Program</key>
<string>%s</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.nuxeo.drive.agentlauncher</string>
<key>RunAtLoad</key>
<true/>
<key>Program</key>
<string>%s</string>
</dict>
</plist>
"""

def _get_agent_file(self):
Expand Down Expand Up @@ -134,7 +131,8 @@ def unregister_protocol_handlers(self):
# Dont unregister, should be removed when Bundle removed
pass

def is_partition_supported(self, folder):
@staticmethod
def is_partition_supported(folder):
if folder is None:
return False
result = False
Expand All @@ -144,20 +142,20 @@ def is_partition_supported(self, folder):
os.mkdir(folder)
if not os.access(folder, os.W_OK):
import stat
os.chmod(folder, stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP |
stat.S_IRUSR | stat.S_IWGRP | stat.S_IWUSR)
os.chmod(folder, stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP
| stat.S_IRUSR | stat.S_IWGRP | stat.S_IWUSR)
import xattr
attr = "drive-test"
attr = 'drive-test'
xattr.setxattr(folder, attr, attr)
if xattr.getxattr(folder, attr) == attr:
result = True
xattr.removexattr(folder, attr)
finally:
try:
if to_delete:
if to_delete:
try:
os.rmdir(folder)
except:
pass
except:
pass
return result

def register_folder_link(self, folder_path, name=None):
Expand All @@ -178,11 +176,11 @@ def register_folder_link(self, folder_path, name=None):
log.warning("Could not fetch the Finder favorite list.")
return

url = CFURLCreateWithString(None, "file://"
url = CFURLCreateWithString(None, 'file://'
+ urllib2.quote(folder_path), None)
if url is None:
log.warning("Could not generate valid favorite URL for: %s",
folder_path)
log.warning('Could not generate valid favorite URL for: %s',
folder_path)
return

# Register the folder as favorite if not already there
Expand Down Expand Up @@ -215,13 +213,17 @@ def unregister_folder_link(self, name):

LSSharedFileListItemRemove(lst, item)

def _get_favorite_list(self):
@staticmethod
def _get_favorite_list():
from LaunchServices import LSSharedFileListCreate
from LaunchServices import kLSSharedFileListFavoriteItems

return LSSharedFileListCreate(None, kLSSharedFileListFavoriteItems, None)
return LSSharedFileListCreate(None,
kLSSharedFileListFavoriteItems,
None)

def _find_item_in_list(self, lst, name):
@staticmethod
def _find_item_in_list(lst, name):
from LaunchServices import LSSharedFileListCopySnapshot
from LaunchServices import LSSharedFileListItemCopyDisplayName

Expand Down
1 change: 0 additions & 1 deletion nuxeo-drive-client/nxdrive/osi/windows/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
__author__ = 'loopingz'
Loading

0 comments on commit fbfe879

Please sign in to comment.