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 main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__ + __doc__) inf0 = open(args[0]) inf1 = open(args[1]) f0 = inf0.read() f1 = inf1.read() i = 0 j = 0 while 1: ch = getChar(f0, i) if ch != f1[j]: print(ch, f1[j], i) l = 0 while ch != f1[j]: i += 1 ch = getChar(f0, i) l += 1 print('recover:', l) i += 1 j += 1 oss.exit(0)
def usage(err): #--------------------------------------------------------------------------- print >> oss.stderr, """ usage: %s -c, --config : specify a configuration filename """ % (gTitle) oss.exit(err)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) if len(args) != 2: usage(1, "Must supply file and host") if args[0] == '-': inf = oss.stdin else: inf = file(args[0], 'rb') buf = re.sub("\r\n", "\n", inf.read()) inf.close() host = args[1] if buf: print "Sending:" print buf print s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, 15153)) s.sendall(buf) s.close() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, 15154)) buf = s.recv(4096) s.close() print "Received:" print buf oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [('r', 'recurse'), ('q', 'quick'), ('s', 'supress')], [('d', 'dir')], [], [('x', 'exts')], __doc__) if not args: opts.usage(1, 'Must specify directories') if len(args) == 1: args.append('.') if opts.dir: args = ['{0}/{1}'.format(a, opts.dir) for a in args] for a in args: if not oss.exists(a): opts.usage(2, '"{0}" does not exist'.format(a)) exts = set(['.{0}'.format(e) for e in opts.exts]) if opts.exts else None p = [] for a0, a1 in util.permutations(len(args)): same = checkDir(args[a0], args[a1], exts, opts.quick, opts.recurse, opts.supress) p.append(' {0} {1} {2}'.format(args[a0], '==' if same else '!=', args[a1])) print('Status:') for i in p: print(i) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [('v', 'verbose')], [('L', 'lib'), ('C', 'cc')], __doc__, longOpMarker='---', shortOpMarker='---') if opts.cc is None: oss.usage(1, __doc__, 'must specify compiler path') if opts.cc in compilerMap: path = compilerMap[opts.cc] if isinstance(path, tuple): opts.cc = path[1] path = path[0] else: opts.cc = 'cl.exe' else: path = oss.getpath(opts.cc) ## get environment env = oss.env.env env['PATH'] = path + ';' + env['PATH'] if opts.lib is not None: env['LIB'] = opts.lib if opts.verbose: print path print opts.cc print opts.lib print args rc = subprocess.call(opts.cc + ' ' + ' '.join(args), env=env, shell=True) oss.exit(rc)
def main(argv): #------------------------------------------------------------------------------- """ options: -s | --seed : specify a seed for the random number generator """ args, opts = oss.gopt(argv[1:], [], [('s', 'seed'), ('r', 'restore')], __doc__) if opts.seed: sd = int(opts.seed) else: ## used for debugging sd = int(time.time()) print(sd, "\n\n") random.seed(sd) disp = display.DisplayFactory('console') while 1: try: if opts.restore: Game().restore(opts.restore) opts.restore = None else: menu(disp) break except player.Notification as n: if n.typ == 'quit': pass elif n.typ == 'restore': opts.restore = n.val oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [('v','verbose')], [('h', 'hdr'), ('m', 'msg'), ('c','cmd')], usage) sa, tp = pnet.ArgsToAddrPort(args) if opts.msg: if isinstance(opts.msg, list): opts.msg = '\r\n'.join(opts.msg) else: opts.msg = util.CvtNewLines(opts.msg, '\r\n') if opts.hdr: opts.hdr = list(opts.hdr) if opts.cmd is None: opts.cmd = 'GET' else: opts.cmd = opts.cmd.upper() if opts.cmd in ['PUT', 'POST']: hdr, s = httpPutPost(sa[0], sa[1], tp[0], tp[1], opts.cmd, opts.msg, opts.hdr, opts.verbose) else: hdr, s = httpCmd(sa[0], sa[1], tp[0], tp[1], opts.cmd, opts.hdr, opts.verbose) print hdr print s oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: drives.py shows the available drives on the system and (free space/total space) """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__) drives = w32.GetLogicalDrives() for i in range(26): if drives & (1 << i): dl = chr(i + ord('A')) rootpath = dl + ':\\' tp = w32.GetDriveType(rootpath) print(" %s:" % dl, S[tp], end='') try: f, t, d = w32.GetDiskFreeSpaceEx(rootpath) if tp == 4: print(" (%s/%s)" % (util.CvtGigMegKBytes(f), util.CvtGigMegKBytes(t)), end='') print(" [%s]" % wnet.WNetGetUniversalName(rootpath, 1)) else: print(" (%s/%s)" % (util.CvtGigMegKBytes(f), util.CvtGigMegKBytes(t))) except: print(" -- not ready") 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 main1(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) #mb = imo.IMAPServer('kirby.fc.hp.com', 'chrish', 'kibsop)') mb = imo.IMAPServer('mail.hp.com', '*****@*****.**', 'kibsop)') print mb.version print mb.capability() print 'Num Messages', mb.numMsgs chk = relib.reHas('[email protected]|[hH]yser') for msgSeqNum in range(1, mb.numMsgs): hdr = mb.getMsgHdr(msgSeqNum) #if msgSeqNum >= 52: # print hdr['to'] tl = hdr.toList() if len(tl) != 1: continue #print msgSeqNum, tl[0] if chk.isIn(tl[0]): mb.store(msgSeqNum, '+FLAGS', '(\\Flagged)') #print "-----------------------------------------------------------" #print 'date:', hdr["date"] #print "subject:", hdr['subject'] #print 'to:', hdr['to'] #print hdr.flags print msgSeqNum mb.close() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: tester <files to test> run an automated test against the specified python files. The files must have one or more functions with '__test__' embedded somewhere in the function name. """ args, opts = oss.gopt(argv[1:], [('v', 'verbose')], [('p', 'package')], main.__doc__) pkg = '' if opts.package is None else opts.package + '.' tried = failed = 0 for a in oss.paths(args): try: print("%-20s" % a, end='') t = test_it(pkg + a.name, opts.verbose) print(" %d tests" % t) tried += t except TesterException: print("failed") failed += 1 print("\nRan %d tests. %d Failed\n" % (tried, failed), file=oss.stderr) if failed: oss.exit(1) oss.exit(0)
def usage(rc, errmsg=""): print >> oss.stderr, __doc__ if errmsg: print >> oss.stderr, """ Error: """ + str(errmsg) oss.exit(rc)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [('h', 'hex'), ('d', 'decimal'), ('o', 'octal')], [], __doc__) disp = "%03x" if opts.decimal: disp = "%3d" elif opts.octal: disp = "%3o" for j in xrange(0,32): for i in xrange(0,8): l = 32*i + j if 0 < l and l < 27 : print (disp + ' : ^%c ') % (l, chr(l + ord('a')-1)), elif l == 0 : print (disp + ' : \\0 ') % l, else: print (disp + ' : %c ') % (l, chr(l)), print '\n', oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: compilexrc [options] <xrc_file> options: -d | --dialog : generate dialog code (default) -a | --app : generate application code -f | --frame : generate frame code -w | --wizard : generate wizard code -p | --panel : generate panel code -m | --mixin : import mixin file, name = <xrc_file>_mixin.py """ args, opts = oss.gopt(argv[1:], [('a', 'app'), ('w', 'wizard'), ('d', 'dialog'), ('m', 'mixin'), ('p', 'panel'), ('f', 'frame')], [], __doc__ + main.__doc__) if not args: oss._usage(1, "must supply xrc file(s)") if opts.app: tflag = 'APP' elif opts.wizard: tflag = 'WIZ' elif opts.dialog: tflag = 'DLG' elif opts.panel: tflag = 'PNL' elif opts.frame: tflag = 'APP' else: tflag = None for infn in oss.paths(args): fn = infn.name xrc = XRCParser(infn, fn) xrc.compileXrc(tflag, opts.mixin) oss.exit(0)
def usage(rc, errmsg=""): print__doc__, file=oss.stderr if errmsg: print(""" Error: """ + str(errmsg), file=oss.stderr) oss.exit(rc)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [('p', 'pat'), ('o', 'output')], __doc__ + main.__doc__) if len(args) == 0: args.append('.') if opts.output: otf = file(opts.output, 'w') else: otf = oss.stdout if opts.pat is None: opts.pat = '*' if ',' in opts.pat: opts.pat = opts.pat.split(',') a = Actions(otf) oss.find(args[0], opts.pat, a.action) if opts.output: otf.close() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [('s', 'start'), ('e', 'end')], usage) start = 0 end = 100000000000000000 if opts.start is not None: start = int(opts.start) if opts.end is not None: end = int(opts.end) inf = file(args[0]) try: otf = file(args[1], 'w') except IndexError: otf = oss.stdout idx = 0 for line in inf: if start <= idx < end: otf.write(line) else: if idx >= end: break idx += 1 otf.close() inf.close() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: coverage.py [options] <module_name> options: -s | --swap : swap the ran and miss marks -u | --useDB : use prior run db if exists -m | --mods : modules to report (accepts multiple) """ args, opts = oss.gopt(argv[1:], [('s', 'swap'), ('u', 'useDB')], [], [], [('m', 'mods')], main.__doc__) if not args: opts.usage(1, 'Specify program or module') rm, mm = ('@', ' ') if opts.swap else (' ', '@') co = cvg.Coverage(args[0], rm, mm, opts.useDB, opts.mods) t, success = co.runTest() print("Tester: ran %d test(s) with %s\n" % (t, ['success', 'failure'][success])) print("Coverage generated files for:") for f in co.genReport(): print(' ', f) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) inf = file(args[0]) id = 0 for line in inf: try: if line[-2] == ':': tokens = split(r'[ :]', line[:-1]) print "\niter itr%d;" % id print "for(; %s.in(%s, itr%d);)" % (tokens[3], tokens[1], id) else: tokens = split(r"[ ,]", line) if tokens[0] == "print": print "cout ", for tok in tokens[1:]: print "<<", tok, print ";" except: pass oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: cvtimage -t <type> file [file ...] converts one or more image files to the specified image file type types include: jpg : jpeg bmp : bitmaps png : gif : (input only) """ args, opts = oss.gopt(argv[1:], [], [('t', 'type')], main.__doc__) if opts.type is None: opts.usage(1, "must specify type") args = oss.paths(args) for a in args: otfn = a.drive_path_name + '.' + opts.type if otfn != a: try: print "Converting", a, "to", otfn Image.open(a).save(otfn) except IOError: print >> oss.stderr, "Cannot convert", a, "to", otfn oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ print(argv) args, opts = oss.gopt(argv[1:], [], [], main.__doc__ + __doc__) la = len(args) print(la) print(args) if not (0 < la < 3): oss.usage(1, "usage: cvt_flv_mp3.py <file_name.flv> [<output_file_name.mp3>]") elif la == 2: pth, fn, ext = oss.splitFilename(args[0]) if not pth: pth = '.' infn = fn + '.flv' print(infn) pth, fn, ext = oss.splitFilename(args[1]) if not pth: pth = '.' outfn = pth + '\\' + fn + '.mp3' else: pth, fn, ext = oss.splitFilename(args[0]) if not pth: pth = '.' infn = fn + '.flv' outfn = pth + '\\' + fn + '.mp3' print("Pulling '%s' from '%s'" % (outfn, infn)) oss.r(FFMPEG % (infn, outfn)) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) cvsdwn = not CvsRootCheck() for f in oss.paths(args): ext = oss.splitext(f).lower() opts = '-kb' if ext in BinExts else '' if cvsdwn: otf = file('CVS/offline', 'a') print >> otf, 'add ' + opts + ' ' + f otf.close() else: if oss.exists('CVS/offline'): inf = file('CVS/offline') for cmd in inf: oss.r('cvs.exe ' + cmd) inf.close() oss.rm('CVS/offline') oss.r('cvs.exe add ' + opts + ' ' + f) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [('i', 'stdin')], [], main.__doc__ + __doc__) inf = open(args[0]) if opts.stdin is None else oss.stdin otf = oss.stdout state = 0 for line in inf: line = unicode(line, 'Latin-1', errors='strict') if line.startswith('//---'): continue for ch in line: if state == 0: if ch in WS: state = 1 otf.write(' ') else: try: otf.write(ch) except UnicodeEncodeError: pass elif state == 1: if ch not in WS: otf.write(ch) state = 0 oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: newerthan.py [options[ <date> options: -i | --ignore : extentions to ignore (may be specified multiple times) finds file newer than the specified data date formats ['%b %d %y', '%b %d %Y', '%B %d %y', '%B %d %Y'] """ args, opts = oss.gopt(argv[1:], [], [], [], [('i', 'ignore')], main.__doc__) td = cvtDateExpr(' '.join(args)) if td is None: opts.usage(1, "Can't parse date") for f in oss.find('.'): bn, _, ext = f.rpartition('.') if ext in set(['bak']) or ext.startswith('bk'): continue s = os.stat(f) fd = datetime.datetime.fromtimestamp(s.st_mtime) if fd > td: print(f) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], []) em = EmailMessage() em.toList() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], []) oss.exit(0)
def usage(rc, errmsg=""): #------------------------------------------------------------------------------- """ provides doc string as usage information """ print >> oss.stderr, __doc__ if errmsg: print >> oss.stderr, "\nError:\n" + str(errmsg) oss.exit(rc)
def main(argv): #------------------------------------------------------------------------------- """ usage: dhcpc.py [options] <mac address> options: -s | --server : specify server to try (default: broadcast) -i | --interface : specify network interface to send request through (default: all) -b | --bcast_reply : set broadcast reply flag dhcpc is a dhcp client. It will retrieve information for the specified mac address. """ args, opts = oss.gopt(argv[1:], [('b', 'bcast_reply')], [('s', 'server'), ('i', 'interface')], main.__doc__) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.settimeout(3) baddr = '255.255.255.255' if opts.server is None else opts.server haddr = opts.interface if opts.interface is not None else '0.0.0.0' bcastFlag = 0 if opts.bcast_reply is None else 0x80 print('Server:', baddr, 'Interface:', haddr) s.bind((haddr, 68)) reqid = random.randint(0, 0xffffffff) req = DHCPPacket() req.op = 1 req.htype = 1 req.hlen = 6 req.flags = bcastFlag req.xid = reqid req.msgType = 3 req.chaddr = util.ConvertMacToInt(args[0]) req.addField('b1', 'END', 255) s.sendto(req.getBin(), (baddr, 67)) while 1: try: data, addr = s.recvfrom(1024) except socket.timeout: break res = DHCPPacket(data) if res.xid == reqid: print('--------------------------') print('Response from:', addr[0], '\n') print(' addr :', util.ConvertIntToAddr(res.yiaddr)) print(' mask :', util.ConvertIntToAddr(res.mask)) print(' router :', util.ConvertIntToAddr(res.router0)) print(' dns :', util.ConvertIntToAddr(res.dns_server0)) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: path [options] options: -m | --move <srcidx> <destidx> : move source idx to destination idx -r | --remove <idx> : remove element specified by idx -a | --append <path> : append a path -i | --insert <idx> <path> : insert path at idx """ args, opts = oss.gopt(argv[1:], [('m', 'move'), ('r', 'remove'), ('a', 'append')], [('i', 'insert')], main.__doc__) if opts.move: try: src = int(args[0]) dst = int(args[1]) except: opts.usage(1, "Incorrect move statement") lst = oss.env['PATH'].split(';') val = lst[src] del lst[src] lst.insert(dst, val) oss.export('PATH=%s' % ';'.join(lst)) elif opts.remove: lst = oss.env['PATH'].split(';') try: for a in args: lst[int(a)] = None lst = [l for l in lst if l] except: opts.usage(1, "Incorrect remove statement") oss.export('PATH=%s' % ';'.join(lst)) elif opts.append: lst = oss.env['PATH'].split(';') for a in args: lst.append(a) oss.export('PATH=%s' % ';'.join(lst)) elif opts.insert: lst = oss.env['PATH'].split(';') lst.insert(int(opts.insert), args[0]) oss.export('PATH=%s' % ';'.join(lst)) else: display() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__) for a in args: clean(a) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], []) # # set up database creating reverse mappings and some aliases # db = dict(DNS_DATABASE) for name, addr in DNS_DATABASE.items(): a, b, c, d = addr.split('.') db[d + '.' + c + '.' + b + '.' + a + '.in-addr.arpa.'] = (name + '.work.', 1) db[name + '.work.'] = (addr, 0) db['m' + d + '.work.'] = (addr, 0) db['h' + d + '.work.'] = (addr, 0) pprint.pprint(db) print() ## start server udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udps.bind(('', 53)) try: while 1: data, addr = udps.recvfrom(1024) data = pbf.BitField(data) opcode, query = getQuery(data) query = unicode(query) print('---\nQuery: ', opcode, '-> "%s"' % query) if opcode != 0: udps.sendto(genError(4, data), addr) continue if query in db: ip_name, ptr = db[query] resp = genResponse(ip_name, ptr, data) udps.sendto(resp, addr) print('Response: %s -> %s' % (query, ip_name)) else: err, aa, addrs, aliases = dns.sendDNSQuery( query[:-1], '192.168.1.1') if err == 0: resp = genResponse(addrs[0], 0, data) udps.sendto(resp, addr) print('Response: %s -> %s' % (query, addrs[0])) else: udps.sendto(genError(3, data), addr) except KeyboardInterrupt: udps.close() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- # # handle options # args, opts = oss.gopt(argv[1:], [('u', 'unittest'), ('m', 'main')], [('t', 'target'), ('f', 'file')], usage) if opts.main: if opts.file is None: opts.file = "makefile" mf = file(opts.file, "w") print >> mf, TOP mf.close() oss.exit(0) if opts.target is None: MAIN = MSMAIN EXE = MSEXE if opts.file is None: opts.file = "mak.inc" # # create the file # mf = file(opts.file, "w") print >> mf, MAIN t_objs = [] if opts.unittest: for f in oss.paths(args): hdrs, objs = GetObjectObjs(f) t_objs.extend(objs) else: t_objs = args print t_objs for f in oss.paths(t_objs): print "f:", f hdrs, objs = GetObjectObjs(f) objs.remove(f) oo = [] for o in oss.paths(objs): oo.append("%s.obj" % o.drive_path_name) ff = f.drive_path_name print >> mf, "#\n# %s\n#" % (ff) print >> mf, EXE % (ff, f, ' '.join(hdrs), f, ff, ' '.join(oo), ff, ff, ff, f, " ".join(hdrs), ff, f, ff) mf.close() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], []) # # set up database creating reverse mappings and some aliases # db = dict(DNS_DATABASE) for name, addr in DNS_DATABASE.items(): a, b, c, d = addr.split('.') db[d + '.' + c + '.' + b + '.' + a + '.in-addr.arpa.'] = (name + '.work.', 1) db[name + '.work.'] = (addr, 0) db['m' + d + '.work.'] = (addr, 0) db['h' + d + '.work.'] = (addr, 0) pprint.pprint(db) print() ## start server udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udps.bind(('', 53)) try: while 1: data, addr = udps.recvfrom(1024) data = pbf.BitField(data) opcode, query = getQuery(data) query = unicode(query) print('---\nQuery: ', opcode, '-> "%s"' % query) if opcode != 0: udps.sendto(genError(4, data), addr) continue if query in db: ip_name, ptr = db[query] resp = genResponse(ip_name, ptr, data) udps.sendto(resp, addr) print('Response: %s -> %s' % (query, ip_name)) else: err, aa, addrs, aliases = dns.sendDNSQuery(query[:-1], '192.168.1.1') if err == 0: resp = genResponse(addrs[0], 0, data) udps.sendto(resp, addr) print('Response: %s -> %s' % (query, addrs[0])) else: udps.sendto(genError(3, data), addr) except KeyboardInterrupt: udps.close() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__ + __doc__) for i in oss.ls(r'C:\windows\fonts\*.ttf'): print(i.split('\\')[-1]) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__ + __doc__) for a in args: processFile(a) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: fret_calc.py <scale_length> """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__ + __doc__) for i in range(1, 25): print("%2d: %5.2f" % (i, fret_pos(float(args[0]), i))) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__) trc = Tracer() trc.on.append(("mindmap.py", 20)) trc.run(args[0]) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = optlib.mopt(argv[1:], [], [('m', 'msg'), ('r', 'rev')], main.__doc__ + __doc__, nonOpStopOp=False, skipUnknownOps=True) msg = opts.get('msg', '') if not args: opts.usage(1) cmd = args[0] cnt = len(args[1:]) files = ' '.join([relativizeName(f) for f in args[1:]]) if cmd == 'add': r(MTNCMD + ' add ' + files) elif cmd == 'cf': if files: r(MTNCMD + ' status ' + files) else: r(MTNCMD + ' status .') elif cmd == 'log': options = '--brief' r(MTNCMD + ' log ' + options + ' ' + files) elif cmd == 'ci': r(MTNCMD + ' ci -m "%s" %s' % (msg, files)) elif cmd == 'up': r(MTNCMD + ' up') elif cmd == 'diff': opt = '--revision ' + opts.rev if opts.rev else '' r(MTNCMD + ' diff --context ' + opt + ' ' + files) elif cmd == 'revert': r(MTNCMD + ' revert --missing ' + files) elif cmd == 'cat': if cnt == 1: opt = '--revision ' + opts.rev if opts.rev else '' r(MTNCMD + ' cat ' + opt + ' ' + files) else: opts.usage(1, "Cat only handles a single file") else: r(MTNCMD + ' ' + cmd + ' ' + files) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) for a in DB: thread.start_new_thread(makeTunnel, a) while 1: time.sleep(5 * 60) 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): #------------------------------------------------------------------------------- """ usage: httpcmd [OPTIONS] <URL> Send an http command to the URL. Cmds include 'get', 'put', 'post' etc. The default 'cmd' is 'GET'. Then dumps the returned status code, headers and body data to stdout. Options: -c | --cmd : specifies the cmd, default is 'GET' -m | --msg : specifies the body of a 'PUT' or 'POST' cmd. Use \\n to represent line breaks or specify each line with a -m. -h | --hdr : specifies a single HTTP hdr. This option may be used more than once -v | --verbose : prints lots of output """ args, opts = oss.gopt(argv[1:], [('v', 'verbose')], [('h', 'hdr'), ('m', 'msg'), ('c', 'cmd')], main.__doc__) if not args: opts.usage(1, "Must specify a URL") sa, tp = pnet.ArgsToAddrPort(args) if opts.msg: if isinstance(opts.msg, list): opts.msg = '\r\n'.join(opts.msg) else: opts.msg = util.CvtNewLines(opts.msg, '\r\n') if opts.hdr: opts.hdr = list(opts.hdr) if opts.cmd is None: opts.cmd = 'GET' else: opts.cmd = opts.cmd.upper() if opts.cmd in ['PUT', 'POST']: hdr, s = httpcmd.httpPutPost(sa[0], sa[1], tp[0], tp[1], opts.cmd, opts.msg, opts.hdr, opts.verbose) else: hdr, s = httpcmd.httpCmd(sa[0], sa[1], tp[0], tp[1], opts.cmd, opts.hdr, opts.verbose) print(hdr) print(s) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [('c', 'count')], usage) if opts.count: p = Permutations(range(int(opts.count))) print len(p.ans), p.ans else: p = Permutations(args) print len(p.ans), p.ans oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [], __doc__ + main.__doc__) choices = range(0, 11) ans = raw_input('Numbers to specialize in: ') print() if ans.strip(): for a in ans.split(): choices.extend([int(a)] * 3) while 1: x = random.choice(choices) y = random.choice(choices) dodiv = random.random() < 0.5 rans = x * y start = time.time() if dodiv: ans = raw_input("%d / %d = " % (rans, y)) if y == 0: continue else: ans = raw_input("%d x %d = " % (x, y)) end = time.time() if ans == 'q': break try: if dodiv: if int(ans) != x: print("Sorry. The correct answer is", x) else: print("Correct! Good Job! took %5.2f seconds" % (end - start)) else: if int(ans) != x * y: print("Sorry. The correct answer is", x * y) else: print("Correct! Good Job! took %5.2f seconds" % (end - start)) except Exception as ex: print(ex) print() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: printbin <num> print the binary of the number """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__) for v in args: pbin(int(v)) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: timer <time in minutes> run a timer with display update for the specifed time in minutes (can be float) """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__) if not args: opts.usage(1, "must specify a time in minutes") smins = 0 waypoints = [] for arg in args: v = float(arg) smins += v waypoints.append(v) print("Total: %6.1f" % smins) st = time.time() print("============") for wp in waypoints: wst = time.time() twp = wp while twp > 0: t = time.time() twp = wp - ((t - wst)/60.0) print("%6.1f minutes left" % twp, end='') print("%6.1f minutes left" % (smins - (t - st)/60.0)) if twp < 0.1: break elif twp < 2: time.sleep(10) else: time.sleep(30) print("-------------") print("============") print("done") print("============") st = time.time() while 1: time.sleep(30) print("%6.1f minutes" % ((st - time.time())/60.0)) oss.exit(0)
def CvsRootCheck(): #------------------------------------------------------------------------------- root = oss.readf('CVS/Root', 0) if root is None: root = oss.env['CVSROOT'] if root[:9] != ':pserver:' and not oss.exists(root): print("CVSROOT('%s') is down" % root) oss.exit(1) print("CVS Root: '%s'" % root)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [], main.__doc__ + __doc__) r = args[0][0:2] g = args[0][2:4] b = args[0][4:6] print(int(r, 16), int(g, 16), int(b, 16)) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: zippy.py zippy can create and extract from various archive formats. Format can normally be deduced from file extensions for extraction, but must be specified for creation. -c | --create <archive> : create a new archive -a | --append <archive> : append files to archive // create/extract archive formats -z | --zip : archive is a zip file -g | --gzip : archive is a gzip -t | --tgz : archive is a gzipped tar file // extract only archive formats -r | --rar : archive is an rar file -p | --path : extraction path for relative file names -l | --list : list contents of archive -v | --verbose : verbose actions """ args, opt = oss.gopt(argv[1:], [('z', 'zip'), ('g', 'gzip'), ('l', 'list'), ('t', 'tgz'), ('r', 'rar'), ('v', 'verbose')], [('a', 'append'), ('c', 'create'), ('p', 'path')], main.__doc__) if opt.path is None: opt.path = '.' ## create or add to an archive if opt.create or opt.append: archive = opt.create if opt.create else opt.append archtype = getType(opt, archive) aa = _Archives[archtype](archive, archtype, verbose=opt.verbose) aa.Create(args, opt.append) return ## explode some archives for archive in args: archtype = getType(opt, archive) aa = _Archives[archtype](archive, archtype, opt.path, opt.verbose) if opt.list: aa.List() continue aa.Extract() oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: """ args, opts = oss.gopt(argv[1:], [], [('n', 'net'), ('m', 'mask')], main.__doc__ + __doc__) mask = util.ConvertNetMaskToInt(opts.mask) net = util.ConvertNetMaskToInt(opts.net) & mask nete = util.ConvertIntToAddr(net + (0xffffffffL - mask)) net = util.ConvertIntToAddr(net) print("Start {0} -> {1}\n".format(net, nete)) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ pinger.py [options] [target] pinger <target> : pings target pinger -m <netmask> -n <network> : pings all addresses on network pinger -n <network CIDR format> : pings all addresses on network pinger -r <target> : raceroute w/ icmp packets pinger -s : run router discovery protocol """ args, opts = oss.gopt(argv[1:], [('r', 'route'), ('s', 'srtr')], [("m", "mask"), ("n", "net")], main.__doc__) if opts.srtr is not None: icmp.RouterDiscoveryProtocol().Solicit() oss.exit(0) if opts.route is not None: print(icmp.Pinger().traceroute(args[0]).results) oss.exit(0) if opts.mask is not None: if opts.net is None: opts.usage(1, "if option 'm' set, 'n' must be set") if opts.net is not None: if opts.mask is None: nn = opts.net if nn[0] == '/': nn = util.getIPAddr() + nn a, m = util.ConvertCIDR(nn) if a is None: opts.usage(1, "options 'n' and 'm' must be set together") opts.net, opts.mask = a, m print(" using mask:", m) mask = util.ConvertNetMaskToInt(opts.mask) net = util.ConvertNetMaskToInt(opts.net) & mask args = [] mask = 0xffffffffL - mask for i in range(1, mask): args.append(util.ConvertIntToAddr(net | i)) print("\nSearching Addresses: %s -- %s, %d" % (args[0], args[-1], mask + 1)) else: if not args: opts.usage(1, "must set an option") p = icmp.Pinger() for k, v in p.ping(args, 25).results.iteritems(): print("%s\t%s" % (k, v)) oss.exit(0) p = icmp.Pinger() print("%s\t---" % util.ConvertIntToAddr(net)) for k, v in p.ping(args).results.iteritems(): print("%s\t%s" % (k, v)) print("%s\t---" % util.ConvertIntToAddr(net + mask)) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- """ usage: utc_time.py [options] options: -p | --pplan : use power plan format """ args, opts = oss.gopt(argv[1:], [('p', 'pplan')], [], main.__doc__ + __doc__) fmtStr = "%Y%m%d_%H%MZ" if opts.pplan else "%Y-%m-%d %H:%M:%SZ" print(time.strftime(fmtStr, time.gmtime())) oss.exit(0)
def main(argv): #------------------------------------------------------------------------------- args, opts = oss.gopt(argv[1:], [], [], usage) s = [3, 1, 0, 4, 8, 6, 9, 9] print s s = HaarWaveletTransform(s) print s s = InverseHaarWaveletTransform(s) print s oss.exit(0)