diff options
-rwxr-xr-x | bin/dotfiles | 2 | ||||
-rw-r--r-- | dotfiles/__init__.py | 1 | ||||
-rw-r--r-- | dotfiles/compat.py | 78 | ||||
-rwxr-xr-x | runtests.py | 9 | ||||
-rw-r--r-- | setup.py | 7 |
5 files changed, 51 insertions, 46 deletions
diff --git a/bin/dotfiles b/bin/dotfiles index 39c95a5..774d6a0 100755 --- a/bin/dotfiles +++ b/bin/dotfiles @@ -1,9 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import os import sys + # Add project root directory (enable symlink, and trunk execution). PROJECT_ROOT_DIRECTORY = os.path.abspath( os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) diff --git a/dotfiles/__init__.py b/dotfiles/__init__.py index 73b00b4..72815b1 100644 --- a/dotfiles/__init__.py +++ b/dotfiles/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ dotfiles ~~~~~~~~ diff --git a/dotfiles/compat.py b/dotfiles/compat.py index c640586..b4a5cf5 100644 --- a/dotfiles/compat.py +++ b/dotfiles/compat.py @@ -16,19 +16,20 @@ else: # symlink, islink, readlink, realpath, is_link_to win32_verbose = False # set to True to debug symlink stuff - import os, ctypes, struct + import os + import ctypes + import struct from ctypes import windll, wintypes FSCTL_GET_REPARSE_POINT = 0x900a8 - FILE_ATTRIBUTE_READONLY = 0x0001 - FILE_ATTRIBUTE_HIDDEN = 0x0002 - FILE_ATTRIBUTE_DIRECTORY = 0x0010 - FILE_ATTRIBUTE_NORMAL = 0x0080 + FILE_ATTRIBUTE_READONLY = 0x0001 + FILE_ATTRIBUTE_HIDDEN = 0x0002 + FILE_ATTRIBUTE_DIRECTORY = 0x0010 + FILE_ATTRIBUTE_NORMAL = 0x0080 FILE_ATTRIBUTE_REPARSE_POINT = 0x0400 - - GENERIC_READ = 0x80000000 + GENERIC_READ = 0x80000000 GENERIC_WRITE = 0x40000000 OPEN_EXISTING = 3 FILE_READ_ATTRIBUTES = 0x80 @@ -42,7 +43,6 @@ else: # FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTI FILE_FLAG_REPARSE_BACKUP = 35651584 - kdll = windll.LoadLibrary("kernel32.dll") CreateSymbolicLinkA = windll.kernel32.CreateSymbolicLinkA CreateSymbolicLinkA.restype = wintypes.BOOLEAN @@ -55,17 +55,16 @@ else: _CreateFileA = windll.kernel32.CreateFileA _DevIoCtl = windll.kernel32.DeviceIoControl _DevIoCtl.argtypes = [ - wintypes.HANDLE, #HANDLE hDevice - wintypes.DWORD, #DWORD dwIoControlCode - wintypes.LPVOID, #LPVOID lpInBuffer - wintypes.DWORD, #DWORD nInBufferSize - wintypes.LPVOID, #LPVOID lpOutBuffer - wintypes.DWORD, #DWORD nOutBufferSize - ctypes.POINTER(wintypes.DWORD), #LPDWORD lpBytesReturned - wintypes.LPVOID] #LPOVERLAPPED lpOverlapped + wintypes.HANDLE, # HANDLE hDevice + wintypes.DWORD, # DWORD dwIoControlCode + wintypes.LPVOID, # LPVOID lpInBuffer + wintypes.DWORD, # DWORD nInBufferSize + wintypes.LPVOID, # LPVOID lpOutBuffer + wintypes.DWORD, # DWORD nOutBufferSize + ctypes.POINTER(wintypes.DWORD), # LPDWORD lpBytesReturned + wintypes.LPVOID] # LPOVERLAPPED lpOverlapped _DevIoCtl.restype = wintypes.BOOL - def CreateSymbolicLink(name, target, is_dir): assert type(name) == type(target) if type(name) == unicode: @@ -73,9 +72,10 @@ else: else: stat = CreateSymbolicLinkA(name, target, is_dir) if win32_verbose: - print("CreateSymbolicLink(name=%s, target=%s, is_dir=%d) = %#x"%(name,target,is_dir, stat)) + print("CreateSymbolicLink(name=%s, target=%s, is_dir=%d) = %#x" % + (name, target, is_dir, stat)) if not stat: - print("Can't create symlink %s -> %s"%(name, target)) + print("Can't create symlink %s -> %s" % (name, target)) raise ctypes.WinError() def symlink(target, name): @@ -91,7 +91,8 @@ else: assert path has_link_attr = GetFileAttributes(path) & FILE_ATTRIBUTE_REPARSE_POINT if win32_verbose: - print("islink(%s): attrs=%#x: %s"%(path, GetFileAttributes(path), has_link_attr != 0)) + print("islink(%s): attrs=%#x: %s" % + (path, GetFileAttributes(path), has_link_attr != 0)) return has_link_attr != 0 def DeviceIoControl(hDevice, ioControlCode, input, output): @@ -106,8 +107,8 @@ else: output_size = len(output) assert isinstance(output, ctypes.Array) bytesReturned = wintypes.DWORD() - status = _DevIoCtl(hDevice, ioControlCode, input, - input_size, output, output_size, bytesReturned, None) + status = _DevIoCtl(hDevice, ioControlCode, input, input_size, output, + output_size, bytesReturned, None) if win32_verbose: print("DeviceIOControl: status = %d" % status) if status != 0: @@ -115,35 +116,37 @@ else: else: return None - def CreateFile(path, access, sharemode, creation, flags): if type(path) == unicode: - return _CreateFileW(path, access, sharemode, None, creation, flags, None) + return _CreateFileW(path, access, sharemode, None, creation, + flags, None) else: - return _CreateFileA(path, access, sharemode, None, creation, flags, None) + return _CreateFileA(path, access, sharemode, None, creation, + flags, None) SymbolicLinkReparseFormat = "LHHHHHHL" - SymbolicLinkReparseSize = struct.calcsize(SymbolicLinkReparseFormat); + SymbolicLinkReparseSize = struct.calcsize(SymbolicLinkReparseFormat) def readlink(path): """ Windows readlink implementation. """ # This wouldn't return true if the file didn't exist, as far as I know. if not islink(path): if win32_verbose: - print("readlink(%s): not a link."%path) + print("readlink(%s): not a link." % path) return None # Open the file correctly depending on the string type. - hfile = CreateFile(path, GENERIC_READ, 0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT) + hfile = CreateFile(path, GENERIC_READ, 0, OPEN_EXISTING, + FILE_FLAG_OPEN_REPARSE_POINT) # MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16384 = (16*1024) buffer = DeviceIoControl(hfile, FSCTL_GET_REPARSE_POINT, None, 16384) CloseHandle(hfile) - # Minimum possible length (assuming length of the target is bigger than 0) + # Minimum possible length (assuming length of target is bigger than 0) if not buffer or len(buffer) < 9: if win32_verbose: - print("readlink(%s): no reparse buffer."%path) + print("readlink(%s): no reparse buffer." % path) return None # Parse and return our result. @@ -178,20 +181,22 @@ else: PrintNameOffset, PrintNameLength, Flags) = struct.unpack(SymbolicLinkReparseFormat, buffer[:SymbolicLinkReparseSize]) - # print tag, dataLength, reserver, SubstituteNameOffset, SubstituteNameLength + # print(tag, dataLength, reserver, SubstituteNameOffset, + # iSubstituteNameLength) start = SubstituteNameOffset + SymbolicLinkReparseSize - actualPath = buffer[start : start + SubstituteNameLength].decode("utf-16") + actualPath = buffer[start: + start + SubstituteNameLength].decode("utf-16") # This utf-16 string is null terminated index = actualPath.find("\0") if index > 0: actualPath = actualPath[:index] - if actualPath.startswith("\\??\\"): # ASCII 92, 63, 63, 92 + if actualPath.startswith("\\??\\"): # ASCII 92, 63, 63, 92 ret = actualPath[4:] # strip off leading junk else: ret = actualPath if win32_verbose: - print("readlink(%s->%s->%s): index(null) = %d"%\ - (path,repr(actualPath),repr(ret),index)) + print("readlink(%s->%s->%s): index(null) = %d" % + (path, repr(actualPath), repr(ret), index)) return ret def realpath(fpath): @@ -200,6 +205,7 @@ else: if rpath is None: return fpath if not os.path.isabs(rpath): - rpath = os.path.abspath(os.path.join(os.path.dirname(fpath), rpath)) + rpath = os.path.abspath(os.path.join(os.path.dirname(fpath), + rpath)) fpath = rpath return fpath diff --git a/runtests.py b/runtests.py index 6b93a4a..56893b3 100755 --- a/runtests.py +++ b/runtests.py @@ -2910,12 +2910,13 @@ import sys import base64 import zlib + class DictImporter(object): def __init__(self, sources): self.sources = sources def find_module(self, fullname, path=None): - if fullname == "argparse" and sys.version_info >= (2,7): + if fullname == "argparse" and sys.version_info >= (2, 7): # we were generated with <python2.7 (which pulls in argparse) # but we are running now on a stdlib which has it, so use that. return None @@ -2942,7 +2943,7 @@ class DictImporter(object): if is_pkg: module.__path__ = [fullname] - do_exec(co, module.__dict__) # noqa + do_exec(co, module.__dict__) # noqa return sys.modules[fullname] def get_source(self, name): @@ -2955,7 +2956,7 @@ if __name__ == "__main__": if sys.version_info >= (3, 0): exec("def do_exec(co, loc): exec(co, loc)\n") import pickle - sources = sources.encode("ascii") # ensure bytes + sources = sources.encode("ascii") # ensure bytes sources = pickle.loads(zlib.decompress(base64.decodebytes(sources))) else: import cPickle as pickle @@ -2966,4 +2967,4 @@ if __name__ == "__main__": sys.meta_path.insert(0, importer) entry = "import pytest; raise SystemExit(pytest.cmdline.main())" - do_exec(entry, locals()) # noqa + do_exec(entry, locals()) # noqa @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from setuptools import setup from dotfiles import __version__ @@ -10,9 +9,9 @@ setup( author_email='jbernard@tuxion.com', description='Easily manage your dotfiles', url='https://github.com/jbernard/dotfiles', - long_description=open('README.rst').read() + '\n\n' + - open('LICENSE.rst').read() + '\n\n' + - open('HISTORY.rst').read(), + long_description=(open('README.rst').read() + '\n\n' + + open('LICENSE.rst').read() + '\n\n' + + open('HISTORY.rst').read()), license='ISC', packages=['dotfiles'], entry_points = ''' |