def guess_overwrite_paths(): """Guess which partitions to overwrite (to hide deleted files)""" # In case overwriting leaves large files, placing them in # ~/.config makes it easy to find them and clean them. ret = [] if 'posix' == os.name: home = os.path.expanduser('~/.cache') if not os.path.exists(home): home = os.path.expanduser("~") ret.append(home) if not same_partition(home, '/tmp/'): ret.append('/tmp') elif 'nt' == os.name: localtmp = expandvars('$TMP') logger = logging.getLogger(__name__) if not os.path.exists(localtmp): logger.warning('%TMP% does not exist: %s', localtmp) localtmp = None else: from win32file import GetLongPathName localtmp = GetLongPathName(localtmp) from Windows import get_fixed_drives for drive in get_fixed_drives(): if localtmp and same_partition(localtmp, drive): ret.append(localtmp) else: ret.append(drive) else: NotImplementedError('Unsupported OS in guess_overwrite_paths') return ret
def guess_overwrite_paths(): """Guess which partitions to overwrite (to hide deleted files)""" # In case overwriting leaves large files, placing them in # ~/.config makes it easy to find them and clean them. ret = [] if 'posix' == os.name: home = os.path.expanduser('~/.cache') if not os.path.exists(home): home = os.path.expanduser("~") ret.append(home) if not same_partition(home, '/tmp/'): ret.append('/tmp') elif 'nt' == os.name: localtmp = os.path.expandvars('$TMP') if not os.path.exists(localtmp): print 'ERROR: %TMP% does not exist:', localtmp localtmp = None else: from win32file import GetLongPathName localtmp = GetLongPathName(localtmp) from Windows import get_fixed_drives for drive in get_fixed_drives(): try: if localtmp and same_partition(localtmp, drive): ret.append(localtmp) else: ret.append(drive) except Exception, e: # see https://github.com/az0/bleachbit/issues/27 # https://bugs.launchpad.net/bleachbit/+bug/1372179 print 'ERROR in same_partition(%s, %s): %s' % (localtmp, drive, e)
def path_to_option(pathname): pathname = os.path.normcase(pathname) if 'nt' == os.name and os.path.exists(pathname): pathname = GetLongPathName(pathname) if ':' == pathname[1]: pathname = pathname[0] + pathname[2:] return pathname
def path_to_option(pathname): """Change a pathname to a .ini option name (a key)""" # On Windows change to lowercase and use backwards slashes. pathname = os.path.normcase(pathname) # On Windows expand DOS-8.3-style pathnames. if 'nt' == os.name and os.path.exists(pathname): pathname = GetLongPathName(pathname) if ':' == pathname[1]: # ConfigParser treats colons in a special way pathname = pathname[0] + pathname[2:] return pathname
def removePathItem(self, item): indexFound = 0 for i, p in enumerate(self.path, 1): try: p1 = os.path.normcase(GetLongPathName(r'{}'.format(p))).rstrip('\\') if p1 == item: indexFound = i break except: pass if indexFound: del self.path[indexFound-1] # try again self.removePathItem(item)
added = [] if 'OSGEO4W_ROOT' not in environ: print("OSGEO4W_ROOT not set") sys.exit(1) if 'OSGEO4W_MAINTAINER' not in environ: print("OSGEO4W_MAINTAINER not set") sys.exit(1) if 'OSGEO4W_REP' not in environ: print("OSGEO4W_REP not set") sys.exit(1) try: rep = GetLongPathName(environ['OSGEO4W_REP']).replace(sep, '/') + '/' except: rep = environ['OSGEO4W_REP'].replace(sep, '/') + '/' if not isdir(rep): print("OSGEO4W repository not found at {}.".format(rep)) sys.exit(1) o4wroot = GetLongPathName(environ['OSGEO4W_ROOT']).replace(sep, '/') + '/' chdir(o4wroot) def listpkg(): proc = subprocess.Popen(['python', '-m', 'pip', 'list'], stdout=subprocess.PIPE)