Example #1
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)
Example #2
0
File: ascii.py Project: chyser/bin
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)
Example #3
0
File: drives.py Project: chyser/bin
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)
Example #4
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)
Example #5
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)
Example #6
0
File: vnc.py Project: chyser/bin
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)
Example #7
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)
Example #8
0
File: perm.py Project: chyser/bin
def main(argv):
    #-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [], usage)

    vn = 5
    pn = 5
    il = range(vn)
    p = permutations.Permutations(il)

    lll = sumList(vn, pn)
    cc = []

    print "creating lists"
    for cap in lll:
        for vml in p.ans:
            co = Collective(pn)
            co.addCap(cap)
            cc.append(co)
            co.create(vml)

    t = {}
    for c in cc:
        t[c.order()] = c

    print "pn:", pn, "vn:", vn
    print pow(pn, vn)
    print len(t.keys())
Example #9
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)
Example #10
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage:
    """
    args, opts = oss.gopt(argv[1:], [], [], main.__doc__)

    oss.exit(0)
Example #11
0
File: mxmdi.py Project: chyser/bin
def appmain(usage, MFrame, CFGNm, title, context=None):
#-------------------------------------------------------------------------------
    """ builds the application and main window
    """

    args, opt = oss.gopt(oss.argv[1:], [], [('c', 'config')], usage)

    ## get configuration
    if opt.config is None:
        gConfig.Open(CFGNm)
    else:
        gConfig.Open(opt.config)

    children = gConfig.Load()

    app = wx.PySimpleApp()
    win = MFrame(None, -1, title, context, pos = gConfig.MainWindowPos, size = gConfig.MainWindowSize,
              style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE | cfg.Flags2Style(gConfig.MainWindowFlags))


    app.SetTopWindow(win)

    ## open configured windows
    for c in children:
        win.Open(c[0], cfg.Flags2Style(c[1]))

    win.LoadConfig(gConfig)
    return app, win
Example #12
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage: dns <name to lookup> <ip addr of nameserver> [<ip addr of nameserver> ...]
    """
    args, opts = oss.gopt(argv[1:], [('d', 'dbgDump')], [],
                          main.__doc__ + __doc__)

    for ns in args[1:]:
        err, authoritive, addrs, aliases = sendDNSQuery(
            args[0], ns, opts.dbgDump)

        print('NameServer:', ns)
        if err == 0:
            print(('Non-a' if not authoritive else 'A') + 'uthorative answer')
            print('IP Addresses:')
            print('   ', addrs)

            if aliases:
                print('Aliases:')
                print('   ', aliases)
        else:
            print('Error:', err)
        print()

    oss.exit(0)
Example #13
0
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)
Example #14
0
def main(argv):
#-------------------------------------------------------------------------------
    """ usage: readlog.py <file> [<file> ...]

        continuously prints new lines added to files (like tail -f)
    """
    args, opts = oss.gopt(argv[1:], [], [], main.__doc__)

    fs = {};  last = None
    while 1:
        for f in args:
            if f not in fs and oss.exists(f):
                if last != f:
                    print('\n%s : -------------' % f)
                    last = f

                print("Opening:", f)
                last = f
                fs[f] = open(f, 'rU')
            else:
                if f in fs:
                    buf = fs[f].read(-1)
                    if buf:
                        if last != f:
                            print('\n%s : -------------' % f)
                            last = f
                        oss.stderr.write(buf)

            time.sleep(0.5)
Example #15
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage: readlog.py <file> [<file> ...]

        continuously prints new lines added to files (like tail -f)
    """
    args, opts = oss.gopt(argv[1:], [], [], main.__doc__)

    fs = {}
    last = None
    while 1:
        for f in args:
            if f not in fs and oss.exists(f):
                if last != f:
                    print('\n%s : -------------' % f)
                    last = f

                print("Opening:", f)
                last = f
                fs[f] = open(f, 'rU')
            else:
                if f in fs:
                    buf = fs[f].read(-1)
                    if buf:
                        if last != f:
                            print('\n%s : -------------' % f)
                            last = f
                        oss.stderr.write(buf)

            time.sleep(0.5)
Example #16
0
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)
Example #17
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)
Example #18
0
def main(argv):
#-------------------------------------------------------------------------------
    """ usage:
    """
    args, opts = oss.gopt(argv[1:], [], [], main.__doc__)

    oss.exit(0)
Example #19
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)
Example #20
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)
Example #21
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)
Example #22
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)
Example #23
0
File: ascii.py Project: chyser/bin
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)
Example #24
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)
Example #25
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)
Example #26
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage:
    """
    args, opts = oss.gopt(argv[1:], [('n', 'names'), ('s', 'same'),
                                     ('d', 'diff'), ('p', 'dump'),
                                     ('v', 'verbose')], [('a', 'attr')],
                          __doc__ + main.__doc__)

    units = UnitDB('unitdb.ini')

    if opts.names:
        pprint.pprint(units.units())

    elif opts.diff:
        print units.diff(args[0], args[1], opts.verbose)

    elif opts.same:
        print units.same()

    elif opts.attr:
        pprint.pprint(units.getAttrs(args[0], opts.attr))

    elif opts.dump:
        print units.get(args[0]).dump()

    else:
        print units.get(args[0])

    oss.exit(0)
Example #27
0
File: cf.py Project: chyser/bin
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)
Example #28
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)
Example #29
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)
Example #30
0
File: cons.py Project: chyser/bin
def main(argv):
#------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [], "")

    if not args:
        args = machs.keys()

    for m in args:
        if m not in machs:
	    print "unknown machine", m
	    continue

        print "Opening", m
	session = oss.r("qdbus org.kde.konsole /Konsole newSession", '$').strip()
        s = oss.r("qdbus org.kde.konsole /Sessions/%s setTitle 1 %s" % (session, m), '|')
        if s.strip():
            print s.rstrip()

        s = oss.r('qdbus org.kde.konsole /Sessions/%s sendText "ssh %s"' % (session, m), '|')
        if s.strip():
            print s.rstrip()

        s = oss.r('~/bin/qdsendnl %s' % session, '|')
        if s.strip():
            print s.rstrip()

        for cmd in machs[m]:
    	    if cmd:
	        s = oss.r('qdbus org.kde.konsole /Sessions/%s sendText "%s"' % (session, cmd), '|')
                if s.strip():
                    print s.rstrip()
	    s = oss.r('~/bin/qdsendnl %s' % session, '|')
            if s.strip():
                print s.rstrip()
Example #31
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)
Example #32
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)
Example #33
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)
Example #34
0
def main(argv):
    #-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [('n', 'nowin'), ('d', 'dbg')],
                          [('f', 'filename')], usage)

    pn = oss.path(args[0])

    cmd = []
    if pn.ext == '.py':
        if opts.nowin:
            cmd.append('python.exe')
        else:
            cmd.append('pythonw.exe')

    if opts.dbg:
        cmd.append('-d')

    if opts.filename is None:
        opts.filename = pn.name + '.bat'
    else:
        if not opts.filename.endswith('.bat'):
            opts.filename += '.bat'

    cmd.append(oss.abspath(args[0]))
    cmd.append('%ARGS%')

    otf = file('C:/bin/' + opts.filename, 'w')

    print >> otf, ArgLoop
    print >> otf, ' '.join(cmd)

    otf.close()

    oss.exit(0)
Example #35
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)
Example #36
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)
Example #37
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)
Example #38
0
def appmain(usage, MFrame, CFGNm, title, context=None):
    #-------------------------------------------------------------------------------
    """ builds the application and main window
    """

    args, opt = oss.gopt(oss.argv[1:], [], [('c', 'config')], usage)

    ## get configuration
    if opt.config is None:
        gConfig.Open(CFGNm)
    else:
        gConfig.Open(opt.config)

    children = gConfig.Load()

    app = wx.PySimpleApp()
    win = MFrame(None,
                 -1,
                 title,
                 context,
                 pos=gConfig.MainWindowPos,
                 size=gConfig.MainWindowSize,
                 style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
                 | cfg.Flags2Style(gConfig.MainWindowFlags))

    app.SetTopWindow(win)

    ## open configured windows
    for c in children:
        win.Open(c[0], cfg.Flags2Style(c[1]))

    win.LoadConfig(gConfig)
    return app, win
Example #39
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)
Example #40
0
File: perm.py Project: chyser/bin
def main(argv):
#-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [], usage)


    vn = 5
    pn = 5
    il = range(vn)
    p = permutations.Permutations(il)

    lll = sumList(vn, pn)
    cc = []

    print "creating lists"
    for cap in lll:
        for vml in p.ans:
            co = Collective(pn)
            co.addCap(cap)
            cc.append(co)
            co.create(vml)

    t = {}
    for c in cc:
        t[c.order()] = c

    print "pn:", pn, "vn:", vn
    print pow(pn, vn)
    print len(t.keys())
Example #41
0
def main(argv):
#-------------------------------------------------------------------------------
    excludes, opts = oss.gopt(argv[1:], [('u', 'updest'), ('p', 'pretend')],
            [('s', 'src'), ('d', 'dest'), ('f', 'filters')], __doc__)

    if not opts.dest:
        opts.usage(1, "Must specify directories")

    src = opts.get('src', '.')
    print "src  =", src
    print "dest =", opts.dest
    print "excludes:", excludes

    if opts.filters is None:
        opts.filters = []
    else:
        if not isinstance(opts.filters, list):
            opts.filters = [opts.filters]
    print "filters:", opts.filters

    if not oss.exists(src):
        opts.usage(2, "Source directory '%s' does not exist" % src)

    if not oss.exists(opts.dest):
        opts.usage(2, "Destination directory '%s' does not exist" % opts.dest)

    if opts.updest:
        dsync.DirSync(src, opts.dest, excludes, opts.filters).UpdateDest(pretend=opts.pretend)
    else:
        dsync.DirSync(src, opts.dest, excludes, opts.filters).SyncDirs(pretend=opts.pretend)
Example #42
0
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)
Example #43
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)
Example #44
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)
Example #45
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage: timecvt.py [options] <time>

        convert times between UTC and other timezones and back

        options:
            -o | --offset   : timezone offset
    """
    args, opts = oss.gopt(argv[1:], [('u', 'utc')], [('o', 'offset')],
                          main.__doc__)

    offset = -4 if opts.offset is None else float(opts.offset)

    isUtc = args[0][-1] == 'Z'

    if not isUtc:
        offset *= -1

    if '_' in args[0]:
        fmt = '%Y%m%d_%H%M%S'
        ln = 15
    else:
        fmt = '%Y-%m-%d %H:%M:%S'
        ln = 19

    dt = datetime.datetime.strptime(args[0][:ln], fmt)

    print(
        str(dt + datetime.timedelta(hours=offset)) +
        ((' UTC%d' % offset) if isUtc else 'Z'))

    oss.exit(0)
Example #46
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)
Example #47
0
File: pycpp.py Project: chyser/bin
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)
Example #48
0
File: pinger.py Project: chyser/bin
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)
Example #49
0
def main(argv):
#-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [])




    oss.exit(0)
Example #50
0
def main(argv):
#-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [])

    em = EmailMessage()
    em.toList()

    oss.exit(0)