def OpenFile(self, FileName, style = 0, lineNum = 0, hndl=None, readOnly=False, fo=None): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - """ Opens the file 'FileName' (path + file) """ if hndl is None: hndl = FileName hndl = oss.canonicalPath(hndl) FileName = oss.canonicalPath(FileName) if self.fileDb.isin(hndl, FileName): ## BUG -- technically this shouldn't be allowed, lets see if it happens assert ptrace(3, "Open: FileName is already in database") pass c = self.CreateChild(FileName, style) fdb = self.fileDb.add(c, hndl, FileName) self.syncFdb(FileName, fdb) try: c.Open(FileName, fdb, fo=fo) c.GotoLine(lineNum) self.sb.SetStatusText("Loaded: " + FileName) except IOError: ErrMsg(self, "Can't Open: " + FileName) c.Destroy() self.fileDb.rm(c) return False self.setChildTitle(c, FileName) return True
def OpenFile(self, FileName, style=0, lineNum=0, hndl=None, readOnly=False, fo=None): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - """ Opens the file 'FileName' (path + file) """ if hndl is None: hndl = FileName hndl = oss.canonicalPath(hndl) FileName = oss.canonicalPath(FileName) if self.fileDb.isin(hndl, FileName): ## BUG -- technically this shouldn't be allowed, lets see if it happens assert ptrace(3, "Open: FileName is already in database") pass c = self.CreateChild(FileName, style) fdb = self.fileDb.add(c, hndl, FileName) self.syncFdb(FileName, fdb) try: c.Open(FileName, fdb, fo=fo) c.GotoLine(lineNum) self.sb.SetStatusText("Loaded: " + FileName) except IOError: ErrMsg(self, "Can't Open: " + FileName) c.Destroy() self.fileDb.rm(c) return False self.setChildTitle(c, FileName) return True
def __init__(self, hndl=None, win=None, fpath=None, primary=True): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - object.__init__(self) self.hndl = hndl self.fpath = hndl if fpath is None else fpath self.win = win self.cxt = None self.order = -1 self.update() self.props = set() self.primary = primary self.fpath = oss.canonicalPath(self.fpath) self.hndl = oss.canonicalPath(self.hndl)
def __init__(self, hndl=None, win=None, fpath=None, primary=True): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - object.__init__(self) self.hndl = hndl self.fpath = hndl if fpath is None else fpath self.win = win self.cxt = None self.order = -1 self.update() self.props = set() self.primary = primary self.fpath = oss.canonicalPath(self.fpath) self.hndl = oss.canonicalPath(self.hndl)
def sizeDir(pth, dirOnly, progress=False): #------------------------------------------------------------------------------- res = [] tsize = 0 if pth == '/' or pth == r'\\': pth += '*' for df in oss.ls(pth): df = oss.canonicalPath(df) if df in gExcludes: print('excluding:', df, file=oss.stderr) continue if progress: print('...', df.encode('utf8', 'ignore')) gVisited.add(df) if os.path.isdir(df): size = calcSize(df, progress) res.append(util.sstruct(size=size, pth=df+'\\')) else: try: size = os.stat(df).st_size except WindowsError as ex: print('Error: "%s"' % str(ex), file=oss.stderr) if not dirOnly: res.append(util.sstruct(size=size, pth=df)) tsize += size res.append(util.sstruct(size=tsize, pth=pth)) res.sort(key=lambda ss: int(ss.size), reverse=True) return res
def calcSize(pth, progress=False, lvl=2): #------------------------------------------------------------------------------- size = 0 for p, d, f in os.walk(pth): for dd in d: dd = oss.canonicalPath(dd) if dd in gExcludes: print('excluding:', dd, file=oss.stderr) continue if dd in gVisited: continue gVisited.add(dd) if progress: print('...'*lvl, dd.encode('utf8', 'ignore')) size += calcSize(pth + '/' + dd, progress, lvl+1) for ff in f: try: s = os.stat(p + '/' + ff)[6] size += s except WindowsError as ex: print('Error: "%s"' % str(ex), file=oss.stderr) return size
def main(argv): #------------------------------------------------------------------------------- """ usage: diskusage [options] [path] calculates the bytes used by the sub directories of the specified path. defaults to the current directory options: -d | --dir_only : show directories only -p | --progress : show progress -x | --exclude : specifiy path to be excluded (can be issued multiple times) """ args, opts = oss.gopt(argv[1:], [('p', 'progress'), ('d', 'dir_only')], [], [], [('x', 'exclude')], main.__doc__) if not args: args = ['.'] if opts.exclude: global gExcludes gExcludes = [oss.canonicalPath('./' + x) for x in opts.exclude] print('Excludes:', gExcludes) for pth in oss.paths(args): for ss in sizeDir(pth, opts.dir_only, opts.progress): print("%8s" % util.CvtGigMegKBytes(ss.size, "1.1"), ss.pth) oss.exit(0)
def sizeDir(pth, dirOnly, progress=False): #------------------------------------------------------------------------------- res = [] tsize = 0 if pth == '/' or pth == r'\\': pth += '*' for df in oss.ls(pth): df = oss.canonicalPath(df) if df in gExcludes: print('excluding:', df, file=oss.stderr) continue if progress: print('...', df.encode('utf8', 'ignore')) gVisited.add(df) if os.path.isdir(df): size = calcSize(df, progress) res.append(util.sstruct(size=size, pth=df + '\\')) else: try: size = os.stat(df).st_size except WindowsError as ex: print('Error: "%s"' % str(ex), file=oss.stderr) if not dirOnly: res.append(util.sstruct(size=size, pth=df)) tsize += size res.append(util.sstruct(size=tsize, pth=pth)) res.sort(key=lambda ss: int(ss.size), reverse=True) return res
def calcSize(pth, progress=False, lvl=2): #------------------------------------------------------------------------------- size = 0 for p, d, f in os.walk(pth): for dd in d: dd = oss.canonicalPath(dd) if dd in gExcludes: print('excluding:', dd, file=oss.stderr) continue if dd in gVisited: continue gVisited.add(dd) if progress: print('...' * lvl, dd.encode('utf8', 'ignore')) size += calcSize(pth + '/' + dd, progress, lvl + 1) for ff in f: try: s = os.stat(p + '/' + ff)[6] size += s except WindowsError as ex: print('Error: "%s"' % str(ex), file=oss.stderr) return size
def main(argv): #------------------------------------------------------------------------------- """ usage: diskusage [options] [path] calculates the bytes used by the sub directories of the specified path. defaults to the current directory options: -d | --dir_only : show directories only -p | --progress : show progress -x | --exclude : specifiy path to be excluded (can be issued multiple times) """ args, opts = oss.gopt(argv[1:], [('p', 'progress'), ('d', 'dir_only')], [], [], [('x', 'exclude')], main.__doc__) if not args: args = ['.'] if opts.exclude: global gExcludes gExcludes = [oss.canonicalPath('./' + x) for x in opts.exclude] print('Excludes:', gExcludes) for pth in oss.paths(args): for ss in sizeDir(pth, opts.dir_only, opts.progress): print("%8s" % util.CvtGigMegKBytes(ss.size, "1.1"), ss.pth) oss.exit(0)
def getChild(self, hndl, fpath=None): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - """ gets the child window associated with hndl """ with self.dblock: hndl = oss.canonicalPath(hndl) fo = self.getFO(hndl=hndl) if fo is not None: return fo.win
def getFO(self, cwin=None, hndl=None, fpath=None): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - with self.dblock: if hndl is not None: hndl = oss.canonicalPath(hndl) if hndl in self.fileObjHndls: return self.fileObjHndls[hndl] if fpath is not None: fpath = oss.canonicalPath(fpath) for fo in self.fileObjHndls.values(): if fo.primary and fpath == fo.fpath: return fo if cwin is not None: for fo in self.fileObjHndls.values(): if cwin == fo.win: return fo
def getChild(self, hndl, fpath=None): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - """ gets the child window associated with hndl """ with self.dblock: hndl = oss.canonicalPath(hndl) fo = self.getFO(hndl = hndl) if fo is not None: return fo.win
def getFO(self, cwin=None, hndl=None, fpath=None): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - with self.dblock: if hndl is not None: hndl = oss.canonicalPath(hndl) if hndl in self.fileObjHndls: return self.fileObjHndls[hndl] if fpath is not None: fpath = oss.canonicalPath(fpath) for fo in self.fileObjHndls.values(): if fo.primary and fpath == fo.fpath: return fo if cwin is not None: for fo in self.fileObjHndls.values(): if cwin == fo.win: return fo
def main(argv): #------------------------------------------------------------------------------- """ usage: myedit.py <files> [<files> ...] frontend to myedit """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__ + __doc__) ff = [oss.canonicalPath(arg) for arg in args] for f in ff: if not oss.exists(f): oss.touch(f) oss.r('C:/python26/python.exe C:/home/chrish/work/myedit/myedit.py -X -s ' + ' '.join(ff)) oss.exit(0)