def RunPrep(path, prgm, argv): #------------------------------------------------------------------------------- fn = fileName = oss.splitnm(prgm) fileName += '.py' globd = {} exec('import sys', globd) ## enable local modules to be found wd = oss.abspath(path) globd['sys'].path[0] = wd oss.cd(wd) ## recreate argv globd['sys'].argv = [fileName] + argv ## change name globd["__name__"] = "__main__" globd["__debug__"] = True sys.path = globd['sys'].path sys.argv = globd['sys'].argv sys.modules['__main__'] = __import__(fn) reload(oss) return fileName, globd
def main(argv): #------------------------------------------------------------------------------- """ usage: cf.py [options] options: -n | --nocheck : don't check for CVSROOT show files in CVS/MTN that are changed in local directory """ args, opt = oss.gopt(oss.argv[1:], [('n', 'nocheck')], [], main.__doc__) if oss.exists('CVS'): if opt.nocheck is None: CvsRootCheck() if not args: oss.r(r'C:\bin\cvs.exe -qn up -A | C:\mksnt\fgrep.exe -v "?"') else: for dir in args: oss.cd(dir) oss.r(r'C:\bin\cvs.exe -qn up -A | C:\mksnt\fgrep.exe -v "?"') elif oss.findFilePathUp('_MTN'): oss.r('mtn status') #print '\nunknown files:' #oss.r('mtn ls unknown') oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [('x', 'extra')], [], main.__doc__ + __doc__) mp = set() oss.cd(MUSIC_PATH) for f in oss.find('.', '*.mp3'): dest = CAR_PATH + f[2:] d = dest.split('\\')[0] + '/' mp.add(f) if not oss.exists(d): oss.mkdir(d) if not oss.exists(dest) or oss.newerthan(f, dest): print(f, dest) cp(f, dest) if opts.extra: oss.cd(CAR_PATH) dp = set() for f in oss.find('.', '*.mp3'): dp.add(f) a = dp - mp for f in a: print(f) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [('r', 'rmtport'), ('l', 'locport')], usage) if opts.locport: locport = int(opts.locport) else: locport = random.randint(5905, 5930) display = locport - 5900 rmtport = 5901 if len(args) != 1: usage(1) if ':' in args[0]: mach, rp = args[0].split(':') rmtport = int(rp) + 5900 else: mach = args[0] if opts.rmtport: rmtport = int(opts.rmtport) t = threading.Thread(target=makeTunnel, args=(locport, mach, rmtport)) t.setDaemon(True) t.start() time.sleep(5) oss.cd("C:/Program Files/tightvnc/") oss.r('vncviewer.exe %s:%d' % ('localhost', display)) oss.exit(0)
def checkPath(path): #------------------------------------------------------------------------------- oss.cd(path) libs = [] covered = set() for i in oss.paths(oss.ls('*.pth')): libs.append(i.name) for line in oss.readf(i): if line.strip().startswith('#'): continue covered.add(line) for i in oss.paths(oss.ls()): if i in covered: continue if i.ext == '.py': libs.append(i.name) if oss.IsDir(i): if oss.exists(i + '/__init__.py'): libs.append(i.name) return libs
def checkPath(path): #------------------------------------------------------------------------------- oss.cd(path) libs = [] covered = set() for i in oss.paths(oss.ls('*.pth')): libs.append(i.name) for line in oss.readf(i): if line.strip().startswith('#'): continue covered.add(line) for i in oss.paths(oss.ls()): if i in covered: continue if i.ext == '.py': libs.append(i.name) if oss.IsDir(i): if oss.exists(i + '/__init__.py'): libs.append(i.name) return libs
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [('x', 'extra')], [], main.__doc__ + __doc__) mp = set() oss.cd(MUSIC_PATH) for f in oss.find('.', '*.mp3'): dest = CAR_PATH + f[2:] d = dest.split('\\')[0] + '/' mp.add(f) if not oss.exists(d): oss.mkdir(d) if not oss.exists(dest) or oss.newerthan(f, dest): print(f, dest) cp(f, dest) if opts.extra: oss.cd(CAR_PATH) dp = set() for f in oss.find('.', '*.mp3'): dp.add(f) a = dp - mp for f in a: print(f) oss.exit(0)
def main(): #------------------------------------------------------------------------------- """ usage: pmake [Options] [<target> [<target> ...]] pmake runs a python interpreter over marked areas of a makefile, then runs the appropriate make command Options: -f | --file <file> : specify makefile -r | --recurse : recurse into subdirectories (first) -C | --directory <dir> : change to directory first -m | --make <cmd> : specify make command to run (ex nmake) -p | --project : build makefile only -D | --define : define variables -P | --pause : pause the window after execution -h | --help : extended help """ args, opts = oss.gopt(oss.argv[1:], [('p', 'project'), ('h', 'help'), ('v', 'verbose'), ('F', 'force'), ('P', 'pause'), ('r', 'recurse')], [('f', 'file'), ('D', 'define'), ('m', 'make'), ('C', 'directory'), ('j', 'jobs'), ('W', 'wait')], main.__doc__) if opts.help: print _HELP_MSG usage(0) jobs = '' if opts.jobs is None else ' -j ' + opts.jobs if opts.directory: print "Changing to directory:", opts.directory try: oss.cd(opts.directory) except WindowsError: usage(1, "Can't find directory") ret = 0 if opts.recurse: for root, dirs, files in os.walk('.', topdown=False): for name in dirs: pth = os.path.join(root, name) oss.pushcd(pth) ret += doFile(pth, opts.file, opts.make, jobs, opts, args) oss.popcd() ret += doFile('.', opts.file, opts.make, jobs, opts, args) if opts.pause: raw_input('pausing ...') if opts.wait: print 'pausing ... (%s secs)' % opts.wait time.sleep(int(opts.wait)) oss.exit(ret)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) if not args: args = ['.'] for dir in args: oss.cd(dir) oss.r('cvs.exe up -d') oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) if not args: args = ['.'] for dir in args: oss.cd(dir) oss.r('cvs.exe up -d') oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [('m', 'msg')], usage) if opts.msg is None: opts.msg = "" if not args: args = ['.'] for dir in args: oss.cd(dir) oss.r('cvs.exe ci -m "%s"' % opts.msg) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [('m', 'msg')], usage) if opts.msg is None: opts.msg = "" if not args: args = ['.'] for dir in args: oss.cd(dir) oss.r('cvs.exe ci -m "%s"' % opts.msg) oss.exit(0)
def findModules(path): #------------------------------------------------------------------------------- oss.cd(path) dirs = set() pyFiles = set() specific = set() nonSpecific = set() for f in oss.ls(): if f.endswith('.py'): pyFiles.add(oss.path(f)) elif f.endswith('.pyd'): specific.add(oss.path(f).name) elif oss.isDir(f) and oss.exists(f + '/__init__.py'): dirs.add(f) elif f.endswith('.pth'): dirs |= readPthFile(f) else: #print('what:', f) pass for f in pyFiles: f = f.name for ff in oss.ls(): if ff.endswith(f + '.pyd'): specific.add(f) break else: nonSpecific.add(f) for d in dirs: code = False for f in oss.find(d): if f.endswith('.pyd') or f.endswith('.dll'): specific.add(clean(d)) break if f.endswith('.py'): code = True else: if code: nonSpecific.add(clean(d)) return specific, nonSpecific
def rawRun(self, cmd, shell=True): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if cmd.startswith('cd '): oss.cd(cmd[3:]) print oss.pwd() return l = [] for ch in cmd: if ch == '*': l.append('\\*') else: l.append(ch) cmd = ''.join(l) if self.dbglvl > 3: print cmd #return os.system(cmd) return subprocess.call(cmd, shell=shell)
def main(argv): #------------------------------------------------------------------------------- """usage: make.py [options] <target> [<target> ...] options: -C | --cd : change dir before running -s | --strict : be strict about dependency existence -f | --file : specify the makefile to use (default: %s) """ usage = oss.mkusage(main.__doc__ % str(MAKEFILE_NAMES)) args, opts = oss.gopt(argv[1:], [('s', 'strict'), ], [('f', 'file'), 'dbg', ('C', 'cd')], usage) mfile = opts.file if opts.file is not None else getFileName() global STRICT, DBG STRICT = opts.strict DBG = opts.dbg if opts.cd is not None: oss.cd(opts.cd) p = Parser() try: p.parse(mfile) except IOError as ex: usage(1, str(ex)) if DBG == 'rules': p.dump() print("="*75, '\n\n') oss.exit(0) if DBG in set(['file', 'tokens']): oss.exit(0) if not args: args = ['default'] try: for arg in args: p.do(arg) except MakeExit as ex: print(ex) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: uncvs [<dir>] Remove CVS from a directory if specified, else the current directory """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__) if args: oss.cd(args[0]) for dd in oss.find('.', 'CVS'): if oss.exists(dd + '/ROOT'): print("Removing:", dd) oss.r("rm -rf " + dd) oss.exit(0)
def doDir(dir = '.'): #------------------------------------------------------------------------------- try: inf = open("CVS/Entries") except IOError: oss.usage(3, "Not a CVS archive") have = set() for line in inf: try: have.add(line.split('/')[1].upper()) except: pass inf.close() ignr = set() try: with open(".cffignore") as igf: for line in igf: ignr.add(line.strip()) except IOError: pass lst = [] for f in oss.ls(): f = oss.basename(f) if ignoreFile(f, ignr): continue if oss.IsDir(f): if not oss.exists(f + '/CVS'): if f.upper() not in have: lst.append("%s/%s/" % (dir, f)) else: opwd = oss.pwd() oss.cd(f) lst.extend(doDir(dir + '/' + f)) oss.cd(opwd) elif f.upper() not in have: lst.append("%s/%s" % (dir, f)) return lst
def doDir(dir='.'): #------------------------------------------------------------------------------- try: inf = open("CVS/Entries") except IOError: oss.usage(3, "Not a CVS archive") have = set() for line in inf: try: have.add(line.split('/')[1].upper()) except: pass inf.close() ignr = set() try: with open(".cffignore") as igf: for line in igf: ignr.add(line.strip()) except IOError: pass lst = [] for f in oss.ls(): f = oss.basename(f) if ignoreFile(f, ignr): continue if oss.IsDir(f): if not oss.exists(f + '/CVS'): if f.upper() not in have: lst.append("%s/%s/" % (dir, f)) else: opwd = oss.pwd() oss.cd(f) lst.extend(doDir(dir + '/' + f)) oss.cd(opwd) elif f.upper() not in have: lst.append("%s/%s" % (dir, f)) return lst
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [('p', 'pause')], [], __doc__ + main.__doc__) install_dir = oss.env['MYEDIT_DIRECTORY'] print('MyEdit installed at: "%s"' % install_dir) print('\nUpdating "myedit"') oss.cd(install_dir) t = oss.r('cvs.exe up -d', '|') printResults(t) print('\nUpdating "pylib"') oss.cd('C:/bin/pylib/pylib') t = oss.r('cvs.exe up -d', '|') printResults(t) print('\nIf MyEdit is running, it must be restarted.') if opts.pause: raw_input('\n<Hit key to continue>') oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: mkcvs [OPTIONS] <dir> Makes a cvs archive from the specified directory Options: -i | --ignore : specify extensions or files or directories to ignore example: -i .bmp -i .jpg or -i badfile """ args, opts = oss.gopt(argv[1:], [], [], [], [('i', 'ignore')], main.__doc__) if not oss.exists(oss.env['CVSROOT']): print "CVSROOT is down" oss.exit(1) if args: oss.cd(args[0]) name = oss.basename(oss.pwd()) if oss.exists(oss.env['CVSROOT'] + '/' + name): print >> oss.stderr, "Already exists:", oss.env['CVSROOT'] + '/' + name oss.exit(1) if opts.ignore is not None: if isinstance(opts.ignore, list): IGNORE_PATTERNS.extend(opts.ignore) else: IGNORE_PATTERNS.append(opts.ignore) il = bldIgnoreList() print "Ignoring Files: '%s'" % il oss.r(r'C:\bin\cvs.exe import %s %s %s %s1' % (il, name, name, name)) oss.cd('..') oss.r("mv %s /tmp/%s.bak" % (name, name)) oss.r(r'C:\bin\cvs.exe co %s' % name) oss.cd(name) for f in oss.ls(): print f oss.r("C:\bin\cf.py") oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: copyit <options> options -o | --once : run through loop once and then halt -d | --dest : specify detination directory -s | --src : specifly source directory """ args, opts = oss.gopt(argv[1:], [('o', 'once')], [('d', 'dest'), ('s', 'src')], main.__doc__) if opts.dest is None: opts.dest = getDir(DEST_DIRS) if opts.src is None: opts.src = getDir(SRC_DIRS) if not oss.exists(opts.dest): opts.usage(1, "Destination dir '%s' doesn't exist" % opts.dest) if not oss.exists(opts.src): opts.usage(1, "Source dir '%s' doesn't exist" % opts.src) print("Destination:", opts.dest) print("Source:", opts.src) oss.cd(opts.src) destDirName = opts.dest + ''.join(map(lambda s: "%02d" % s, time.localtime()[:6])) print("Making", destDirName) oss.mkdir(destDirName) xfrc = XferFileClass() id = fileCount = idx = 0 doneMsg = False while 1: done = True files = oss.ls() if not files: if not doneMsg: print('\n--- All files Done ---') doneMsg = True else: doneMsg = False for ef in files: if oss.isDir(ef): continue ext = oss.splitext(ef) ## mozzilla if ext in IGNORE_EXTENSIONS: continue fn = destDirName + '/%08d' % (id) + ext fs = xfrc.xferFile(ef, fn) if fs: print(' xfer: %s <-- %s, %d' % (fn, ef, fs)) fileCount += 1 else: done = False id += 1 if done and opts.once: break ch = util.delayKey(DELAY_TIME) if ch in ['q', 'Q']: break elif ch == 'x': pprint.pprint(xfrc.xfers) elif ch == 'p': print('pausing') while util.delayKey(1000) == None: pass print('\npausing stopped') idx += 1 if idx > 30: idx = 0 xfrc.bad = set() if fileCount == 0: print("Removing unused directory '%s'" % destDirName) oss.rmdir(destDirName) else: print("Copied %d files" % fileCount) print('Bad Files:', xfrc.bad)
def cd(self): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - print(self.path) oss.mkdirs(self.path) oss.cd(self.path)
import pylib.osscripts as oss oss.cd('/home/chrish/tmp') for f in oss.ls('*.st'): d = f.split('.')[:-3] f = '.'.join(d) + '.html' d = f.split('_') nm = d[0] f = '_'.join(d[1:]) print 'http://xhamster.com/movies/' + nm + '/' + f
def main(argv): #------------------------------------------------------------------------------- """ usage: autoflv [options] options: -p | --print : print directory path -c | --count <n> : num files for client to getf -l | --load : show files the need to be loaded -Z | --connect : client stay connected -P | --pause : pause on errors before exit -F | --failed : cleanup failed files -A | --admin <cmd> : execute admin 'cmd' -n | --num_connections <n>: number of simultaneous connections -s | --speed <n> : max speed in bytes per sec """ args, opts = oss.gopt(argv[1:], [('r', 'run'), ('P', 'pause'), ('p', 'print'), ('F', 'failed'), ('l', 'load'), ('Z', 'connect'), ('R', 'readOnly')], [('n', 'num_connections'), ('s', 'speed'), ('c', 'count'), ('A', 'admin')], main.__doc__ + __doc__) # # dump the path # if opts.print: print(FPATH) print(LFILE) oss.exit(0) # # handle any prior failed files # if opts.failed: HandleFailedFiles() oss.exit(0) # # do admin # if opts.admin: admin(opts.admin, opts.readOnly, args) oss.exit(0) cnt = int(opts.count) if opts.count else None # # If a server running, start as a client # serveDB = xmlrpclib.ServerProxy('http://localhost:3783/') try: # # try to open as a client # fdb = None client = random.randint(1, 0xfffffff) print('client (0x%07x) -- version %s' % (client, serveDB.version())) serveDB.login(client) except socket.error: # # open as the master # client = 0 fdb = FileDB(DBFILE, readOnly=opts.readOnly) checker = Checker(LFILE, fdb) util.startDaemonThread(checker.checkPeriodically) serveDB = ServeDB(fdb) util.startDaemonThread(ServerSetup, serveDB) ## fail inprogress for v in fdb.getItems(lambda v: v.inprog): print("'%s' was in-progress, now failed" % v.name) fdb.update(v.name, failed=True, inprog=False) fdb.save() ## check for failed failed = fdb.getItems(lambda v: v.failed) if failed: util.startDaemonThread(WriteFailedFiles, failed, argv[0]) time.sleep(1) # # dump out the current load list # if opts.load: l = serveDB.getNeedLoaded() print('Not Loaded: %d' % len(l)) for name in l: print(' - %s' % name) if client: serveDB.logout(client) oss.exit() if opts.num_connections is None: opts.num_connections = '4' if opts.speed is None: opts.speed = '400000' # bytes per sec oss.cd(WD) ct = util.TimeElapsed() success = []; failed = [] try: while cnt is None or cnt > 0: v = serveDB.getNext() if v: name = v[0] print('\n>>> getting: "%s"\n' % name) res = getFile(name, v[1], opts.num_connections, opts.speed) if res: success.append(name) serveDB.success(name) else: failed.append(name) serveDB.failed(name) elif client and opts.connect is None: break if ct.check(60): if client: print('... waiting') else: print('... waiting -- %d' % serveDB.getNumClients()) if cnt: cnt -= 1 ch = util.delayKey(1) if ch == 'q': break finally: if fdb: fdb.close() if client: serveDB.logout(client) print('client 0x%07x exiting' % client) else: if serveDB.getNumClients() > 0: print('Still Running Clients: ') for c in serveDB.clients.keys(): print(" 0x%07x" % c) print() print('\nSuccess:', len(success)) print(' \n'.join(success)) ff = len(failed) if ff: print('\nFailed:', ff) print(' \n'.join(failed)) if opts.pause: raw_input('----- PAUSE ------') oss.exit(10) oss.exit(0)
def BUILTIN_cd(s): #------------------------------------------------------------------------------- oss.cd(s)
def real_execute(self, tgt, cmds): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - script = [] args = prgm = eof = strip = None state = 0 env = dict(self.parent.mobj.env) oss.cd(self.parent.curDir) for line in cmds: if state == 0: if '<<<' in line: state = 1 strip, line = util.leadingSpaces(line) a, eof = relib.split('<<<', line) prgm = a[0] try: args = a[1:] except IndexError: args = [] else: line = line.strip() if line: s = line.split(' ', 1) if s[0] in BUILTINS: BUILTINS[s[0]](s[1]) elif s[0] == 'set': try: var, _, val = s[1].partition('=') var = var.strip().encode('ascii', 'ignore') if _ == '=': val = val.strip().encode('ascii', 'ignore') env[var] = val else: print(var, '=', env[var]) except IndexError: pprint.pprint(env) elif s[0] == 'call': cmd = self.parent.evalPython(s[1]) if cmd is not None: self.runCmd(tgt, cmd, env) else: self.runCmd(tgt, line, env) elif state == 1: if line.strip() == eof[0]: otf = tempfile.NamedTemporaryFile(delete=False) name = otf.name otf.writelines(script) otf.close() try: self.runCmd(tgt, prgm + ' ' + name + ' ' + ' '.join(args), env, True) finally: oss.rm(name) script = [] args = prgm = eof = strip = None state = 0 else: ln = line[strip:] if len(ln) == 0: ln = '\n' script.append(ln) self.complete.set()