示例#1
0
    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)
示例#2
0
    def __init__(self):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        object.__init__(self)
        self.rules = RuleSet()
        self.symbols = {}
        self.lineNum = 0

        self.mobj = self.MObj(self.symbols)
        self.codeEnv = {'mobj' : self.mobj}

        self.curDir = oss.pwd()
示例#3
0
文件: cff.py 项目: chyser/bin
def main(argv):
    #-------------------------------------------------------------------------------
    """
    usage: cff
        -i | --ignore      : ignore this file (or filespec)
        -l | --ignorelist  : dump list of ignored files
        -a | --add         : add the files to CVS

    list the files that have NOT been checked into the CVS archive

    """
    args, opts = oss.gopt(argv[1:], [('l', 'ignorelist'), ('a', 'add')], [],
                          [], [('i', 'ignore')], main.__doc__)

    if oss.exists('CVS'):
        if opts.ignore:
            with open(".cffignore", "a") as igf:
                for i in opts.ignore:
                    print(i, file=igf)
                oss.exit(0)

        if opts.add is not None:
            lst = doDir()
            for l in lst:
                print('cvs add ' + oss.basename(l))
                oss.r('cvs add ' + oss.basename(l))
            oss.exit(0)

        if opts.ignorelist is not None:
            lst = list(mkcvs.IGNORE_PATTERNS)
            with open(".cffignore") as igf:
                for line in igf:
                    line = line[:-1]
                    lst.append(line)
            print(lst)

        lst = doDir()
        for l in lst:
            print(l)

    else:
        print('montone')
        pth = oss.findFilePathUp('_MTN')

        if pth:
            lst = oss.r('mtn ls unknown', '|').split('\n')
            pwd = oss.normpath(oss.pwd())

            for i in lst:
                if (pth + i).startswith(pwd):
                    print(i)

    oss.exit(0)
示例#4
0
文件: cff.py 项目: chyser/bin
def main(argv):
#-------------------------------------------------------------------------------
    """
    usage: cff
        -i | --ignore      : ignore this file (or filespec)
        -l | --ignorelist  : dump list of ignored files
        -a | --add         : add the files to CVS

    list the files that have NOT been checked into the CVS archive

    """
    args, opts = oss.gopt(argv[1:], [('l', 'ignorelist'), ('a', 'add')], [], [], [('i', 'ignore')], main.__doc__)

    if oss.exists('CVS'):
        if opts.ignore:
            with open(".cffignore", "a") as igf:
                for i in opts.ignore:
                    print(i, file=igf)
                oss.exit(0)

        if opts.add is not None:
            lst = doDir()
            for l in lst:
                print('cvs add ' + oss.basename(l))
                oss.r('cvs add ' + oss.basename(l))
            oss.exit(0)

        if opts.ignorelist is not None:
            lst = list(mkcvs.IGNORE_PATTERNS)
            with open(".cffignore") as igf:
                for line in igf:
                    line = line[:-1]
                    lst.append(line)
            print(lst)

        lst = doDir()
        for l in lst:
            print(l)

    else:
        print('montone')
        pth = oss.findFilePathUp('_MTN')

        if pth:
            lst = oss.r('mtn ls unknown', '|').split('\n')
            pwd = oss.normpath(oss.pwd())

            for i in lst:
                if (pth + i).startswith(pwd):
                    print(i)

    oss.exit(0)
示例#5
0
文件: mkcvs.py 项目: chyser/bin
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)
示例#6
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage: mk_cmd_help.py [options] [<file_name> ...]

        options:
            -o | --output    : html file output <default: 'cmd_help.html'

        generate an html output file of the help strings from the specified
        commands

    """
    args, opts = oss.gopt(argv[1:], [], [('o', 'output')],
                          main.__doc__ + __doc__)

    outfile = 'cmd_help.html' if opts.output is None else opts.output

    if len(args) == 0:
        args = oss.ls('*.py')

    title = oss.pwd()

    print("Writing to file: '%s'" % outfile)
    with open(outfile, 'w') as otf:
        otf.write(HTML_BEGIN % (title, title))

        ## make a table of links to prgms details
        links = ['<a href="#{0}">{0}</a>'.format(nm) for nm in args]
        otf.write('<a name="top"><h2>Contents</h2></a>\n')
        otf.write("<center>\n" +
                  utils.makeTable(links, tattr='border="1" width="90%"') +
                  "\n</center>\n\n")
        otf.flush()

        ## make an entry for each prgms details
        for prgm in args:
            print(prgm)
            otf.write('\n\n<hr/>\n')
            otf.write('<a name="{0}">'.format(prgm))
            otf.write('<h2>' + prgm + '</h2></a>\n')
            s = oss.r(prgm + ' --help', '$')
            otf.write('<font size="5"><pre>' + cgi.escape(s) +
                      '</pre></font>\n')
            otf.write('<a href="#top">Top</a>\n')
            otf.flush()
        otf.write(HTML_END)
    oss.exit(0)
示例#7
0
文件: cff.py 项目: chyser/bin
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
示例#8
0
文件: cff.py 项目: chyser/bin
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
示例#9
0
文件: mycvs.py 项目: chyser/bin
    def create(self, args, opts):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        if not self.cvsup:
            print('CVS Archive "%s" is down' % self.root, file=oss.stderr)
            return

        name = args[0] if args else oss.basename(oss.pwd())

        if not self.root.startswith(':pserver:'):
            if oss.exists(self.root + '/' + name):
                if opts.force:
                    pass
                else:
                    print('CVS Archive "%s" exists' % name, file=oss.stderr)
                    return

        msg = opts.msg if opts is not None else 'Initial Checkin: ' + name

        questionable = set([ '*' + ext for ext in self.QuestionableExtensions])
        binaries = set([ '*' + ext for ext in self.BinExts])
        il = "-I! " + ' '.join([ '-I "%s"' % pat for pat in (self.IgnorePatterns | questionable | binaries)])
        oss.r(self.exe + ' import -m"%s" %s %s %s %s1' % (msg, il, name, name, name))

        self.co(None, opts)
示例#10
0
文件: mvmusic.py 项目: chyser/bin
def main(argv):
#-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [('d', 'dup'), ('s', 'show')], [], __doc__)

    ign = getIgnoreSet()

    print("Cur Dir:", oss.pwd())
    for i in oss.find('.', '*.mp3'):
        ii = id3.ID3(i)
        err = True

        try:
            artist = translate(ii['ARTIST'])

            if artist in ['*', '<<unknown artist>>']:
                print(i, "artist name error: *")
                raise MyException('artist name error')

            if artist in ign:
                continue

            title = translate(ii['TITLE'])

            dir = BU_PATH + '/' + artist
            try:
                if not oss.exists(dir):
                    oss.mkdir(dir)
            except IOError as ex:
                print(i, "IOError: %s" % str(ex))
                raise MyException('artist name error')
            except TypeError as ex:
                print(i, "IOError: %s" % str(ex))
                raise MyException('artist name error')

            fn = dir + '/' + title + '.mp3'
            if not oss.exists(fn):
                print('%s --> %s' % (i, fn))
                if not opts.show:
                    cp(i, fn)
            elif opts.dup and not oss.cmp(i, fn):
                raise MyException('duplicate song')

            err = False

        except KeyError as ex:
            print('%s -- KeyError: %s' % (i, str(ex)))
        except UnicodeDecodeError as ex:
            print('%s -- UnicodeDecodeError: %s' % (i, str(ex)))
        except IOError as ex:
            print('%s -- IOError: %s' % (i, str(ex)))
        except TypeError as ex:
            print('%s -- TypeError: %s' % (i, str(ex)))
        except MyException as ex:
            print('%s -- MyExceptionError: %s' % (i, str(ex)))

        if 0 and err:
            dir = BU_PATH + '/id3_errors'
            f = dir + '/' + oss.basename(i)
            if not oss.exists(f):
                print('error:', i)
                cp(i, f)

    oss.exit(0)
示例#11
0
文件: mvmusic.py 项目: chyser/bin
def main(argv):
    #-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [('d', 'dup'), ('s', 'show')], [], __doc__)

    ign = getIgnoreSet()

    print("Cur Dir:", oss.pwd())
    for i in oss.find('.', '*.mp3'):
        ii = id3.ID3(i)
        err = True

        try:
            artist = translate(ii['ARTIST'])

            if artist in ['*', '<<unknown artist>>']:
                print(i, "artist name error: *")
                raise MyException('artist name error')

            if artist in ign:
                continue

            title = translate(ii['TITLE'])

            dir = BU_PATH + '/' + artist
            try:
                if not oss.exists(dir):
                    oss.mkdir(dir)
            except IOError as ex:
                print(i, "IOError: %s" % str(ex))
                raise MyException('artist name error')
            except TypeError as ex:
                print(i, "IOError: %s" % str(ex))
                raise MyException('artist name error')

            fn = dir + '/' + title + '.mp3'
            if not oss.exists(fn):
                print('%s --> %s' % (i, fn))
                if not opts.show:
                    cp(i, fn)
            elif opts.dup and not oss.cmp(i, fn):
                raise MyException('duplicate song')

            err = False

        except KeyError as ex:
            print('%s -- KeyError: %s' % (i, str(ex)))
        except UnicodeDecodeError as ex:
            print('%s -- UnicodeDecodeError: %s' % (i, str(ex)))
        except IOError as ex:
            print('%s -- IOError: %s' % (i, str(ex)))
        except TypeError as ex:
            print('%s -- TypeError: %s' % (i, str(ex)))
        except MyException as ex:
            print('%s -- MyExceptionError: %s' % (i, str(ex)))

        if 0 and err:
            dir = BU_PATH + '/id3_errors'
            f = dir + '/' + oss.basename(i)
            if not oss.exists(f):
                print('error:', i)
                cp(i, f)

    oss.exit(0)
示例#12
0
文件: simxfer.py 项目: chyser/bin
def main(argv):
#-------------------------------------------------------------------------------
    """ usage: simxfer.py [options] <src_file> [<src_file> ...]

    src_file can be a file name(s) with or without wildcards or a directory. It
    cannot contain path elements

    options:
        -t | --to    : xfer the src file 'src_file' to 'dest_file' on remote system
        -f | --from  : xfer src file on remote system to local file dest_file
        -m | --mach  : spcify machine flu-01 or flu-02. default = flu-02
    """
    usage = oss.mkusage(main.__doc__)
    args, opts = oss.gopt(argv[1:], [('t', 'to'), ('f', 'from_'), ('l', 'list'), ('d', 'dbg')], [('m', 'mach')], usage, expandWildCards=False)

    if len(args) < 1:
        usage(1, 'must specify a target(s)')
        oss.exit(0)

    if opts.dbg:
        global DBG
        DBG = True

    l, a = getPath(oss.pwd(), 'sim', 0)
    a += '/'

    mach = 'flu-02' if opts.mach is None else opts.mach
    mp = machines[mach]

    if opts.list:
        r(SSH + SSH_OPTIONS + mp[0] + ' ls -xp "' + mp[1] + a + args[0] + '"')
        oss.exit(0)

    scpPath = mp[0] + ':' + mp[1]

    if '/' in args[0]:
        usage(2, "target cannot be a path")

    if opts.to:
        for arg in args:
            localFile = l + a + arg
            if oss.isDir(localFile):
                r(SCP + OPTIONS + localFile + ' "' + scpPath + a + arg + '"')
            else:
                r(SCP + OPTIONS + localFile + ' "' + scpPath + a + '"')

        oss.exit(0)

    if opts.from_:
        for arg in args:
            localFile = l + a + arg
            if oss.isDir(localFile):
                r(SCP + OPTIONS + ' "' + scpPath + a + arg + '" ' + localFile)
            else:
                r(SCP + OPTIONS + ' "' + scpPath + a + arg + '" ' + '.')

        oss.exit(0)


    r(SSH + SSH_OPTIONS + mp[0] + ' ls -xp "' + mp[1] + a + args[0] + '"')
    oss.exit(0)
示例#13
0
文件: mtn.py 项目: chyser/bin
def relativizeName(nm):
#-------------------------------------------------------------------------------
    p = oss.pwd()
    return oss.relativePath(p, nm)
示例#14
0
文件: simxfer.py 项目: chyser/bin
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage: simxfer.py [options] <src_file> [<src_file> ...]

    src_file can be a file name(s) with or without wildcards or a directory. It
    cannot contain path elements

    options:
        -t | --to    : xfer the src file 'src_file' to 'dest_file' on remote system
        -f | --from  : xfer src file on remote system to local file dest_file
        -m | --mach  : spcify machine flu-01 or flu-02. default = flu-02
    """
    usage = oss.mkusage(main.__doc__)
    args, opts = oss.gopt(argv[1:],
                          [('t', 'to'), ('f', 'from_'), ('l', 'list'),
                           ('d', 'dbg')], [('m', 'mach')],
                          usage,
                          expandWildCards=False)

    if len(args) < 1:
        usage(1, 'must specify a target(s)')
        oss.exit(0)

    if opts.dbg:
        global DBG
        DBG = True

    l, a = getPath(oss.pwd(), 'sim', 0)
    a += '/'

    mach = 'flu-02' if opts.mach is None else opts.mach
    mp = machines[mach]

    if opts.list:
        r(SSH + SSH_OPTIONS + mp[0] + ' ls -xp "' + mp[1] + a + args[0] + '"')
        oss.exit(0)

    scpPath = mp[0] + ':' + mp[1]

    if '/' in args[0]:
        usage(2, "target cannot be a path")

    if opts.to:
        for arg in args:
            localFile = l + a + arg
            if oss.isDir(localFile):
                r(SCP + OPTIONS + localFile + ' "' + scpPath + a + arg + '"')
            else:
                r(SCP + OPTIONS + localFile + ' "' + scpPath + a + '"')

        oss.exit(0)

    if opts.from_:
        for arg in args:
            localFile = l + a + arg
            if oss.isDir(localFile):
                r(SCP + OPTIONS + ' "' + scpPath + a + arg + '" ' + localFile)
            else:
                r(SCP + OPTIONS + ' "' + scpPath + a + arg + '" ' + '.')

        oss.exit(0)

    r(SSH + SSH_OPTIONS + mp[0] + ' ls -xp "' + mp[1] + a + args[0] + '"')
    oss.exit(0)
示例#15
0
文件: mtn.py 项目: chyser/bin
def relativizeName(nm):
    #-------------------------------------------------------------------------------
    p = oss.pwd()
    return oss.relativePath(p, nm)