Example #1
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 #2
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 #3
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 #4
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 #5
0
def backup():
    #-------------------------------------------------------------------------------
    for f in oss.find(MUSIC_PATH, '*.mp3'):
        print(f)

        ff = BU_PATH + '\\' + oss.basename(f)
        if not oss.exists(ff):
            print('   ', "copied")
            cp(f, ff)
Example #6
0
def backup():
#-------------------------------------------------------------------------------
    for f in oss.find(MUSIC_PATH, '*.mp3'):
        print(f)

        ff = BU_PATH + '\\' + oss.basename(f)
        if not oss.exists(ff):
            print('   ', "copied")
            cp(f, ff)
Example #7
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage:
    """
    args, opts = oss.gopt(argv[1:], [('s', 'sync'), ('d', 'dup')], [],
                          main.__doc__ + __doc__)

    path = AMAZON_PATH
    tbl = string.maketrans('/\',', '-  ')

    for i in oss.find(path, '*.mp3'):
        ii = id3.ID3(i)
        try:
            title = chkName(ii['TITLE'])
            artist = chkName(ii['ARTIST'])
            print(artist, '---', title)

            if opts.sync:
                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))
                    cp(i, fn)
                elif opts.dup and not oss.cmp(i, fn):
                    raise MyException('duplicate song')

        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)))

    oss.exit(0)
Example #8
0
def findModules(path):
    #-------------------------------------------------------------------------------
    oss.cd(path)

    dirs = set()
    pyFiles = set()
    specific = set()
    nonSpecific = set()

    for f in oss.ls():
        if f.endswith('.py'):
            pyFiles.add(oss.path(f))

        elif f.endswith('.pyd'):
            specific.add(oss.path(f).name)

        elif oss.isDir(f) and oss.exists(f + '/__init__.py'):
            dirs.add(f)

        elif f.endswith('.pth'):
            dirs |= readPthFile(f)

        else:
            #print('what:', f)
            pass

    for f in pyFiles:
        f = f.name
        for ff in oss.ls():
            if ff.endswith(f + '.pyd'):
                specific.add(f)
                break
        else:
            nonSpecific.add(f)

    for d in dirs:
        code = False
        for f in oss.find(d):
            if f.endswith('.pyd') or f.endswith('.dll'):
                specific.add(clean(d))
                break
            if f.endswith('.py'):
                code = True
        else:
            if code:
                nonSpecific.add(clean(d))

    return specific, nonSpecific
Example #9
0
def main(argv):
#-------------------------------------------------------------------------------
    """ usage:
    """
    args, opts = oss.gopt(argv[1:], [('s', 'sync'), ('d', 'dup')], [], main.__doc__ + __doc__)

    path = AMAZON_PATH
    tbl = string.maketrans('/\',', '-  ')

    for i in oss.find(path, '*.mp3'):
        ii = id3.ID3(i)
        try:
            title = chkName(ii['TITLE'])
            artist = chkName(ii['ARTIST'])
            print(artist, '---', title)

            if opts.sync:
                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))
                    cp(i, fn)
                elif opts.dup and not oss.cmp(i, fn):
                    raise MyException('duplicate song')

        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)))

    oss.exit(0)
Example #10
0
File: uncvs.py Project: chyser/bin
def main(argv):
#-------------------------------------------------------------------------------
    """
    usage: uncvs [<dir>]

    Remove CVS from a directory if specified, else the current directory
    """
    args, opts = oss.gopt(argv[1:], [], [], main.__doc__)

    if args:
        oss.cd(args[0])

    for dd in oss.find('.', 'CVS'):
        if oss.exists(dd + '/ROOT'):
            print("Removing:", dd)
            oss.r("rm -rf " + dd)

    oss.exit(0)
Example #11
0
    def Create(self, files, doAppend=None):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        if doAppend:
            attr = 'a'
            self.vp("Appending: " + self.name +'\n')
        else:
            attr = 'w'
            self.vp("Creating: " + self.name + '\n')

        zf = zipfile.ZipFile(self.name, attr)
        allfiles = list(files)
        for fname in files:
            if oss.IsDir(fname):
                allfiles.extend(oss.find(fname))

        for fname in allfiles:
            if oss.IsDir(fname):
                continue
            zf.write(fname)
        zf.close()
        return True
Example #12
0
def getSongs(path, verbose=None):
#-------------------------------------------------------------------------------
    m = set()
    d = {}

    for i in oss.find(path, '*.mp3'):
        if verbose:
            print('*', end='')

        ii = id3.ID3(i)
        try:
            tag = ii['ARTIST'] + '/' + ii['TITLE']
            m.add(tag)
            d[tag] = i
        except KeyError:
            pass
        except UnicodeDecodeError:
            pass

    if verbose:
        print('\n')
    return m, d
Example #13
0
def getSongs(path, verbose=None):
    #-------------------------------------------------------------------------------
    m = set()
    d = {}

    for i in oss.find(path, '*.mp3'):
        if verbose:
            print('*', end='')

        ii = id3.ID3(i)
        try:
            tag = ii['ARTIST'] + '/' + ii['TITLE']
            m.add(tag)
            d[tag] = i
        except KeyError:
            pass
        except UnicodeDecodeError:
            pass

    if verbose:
        print('\n')
    return m, d
Example #14
0
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)
Example #15
0
def main(argv):
#-------------------------------------------------------------------------------
    """ usage:
    """
    args, opts = oss.gopt(argv[1:], [('f', 'force'), ('r', 'readonly'), ('m', 'makecmd')], [('c', 'cmdfile')], main.__doc__ + __doc__)

    global BUILD_PATH, CLASS_PATH


    if opts.cmdfile:
        if opts.makecmd and not oss.exists(opts.cmdfile):
            oss.touch(opts.cmdfile)

        with open(opts.cmdfile) as inf:
            dd = yaml.load(inf.read())
            if dd is None:
                dd = {}

            slist = dd['files'] if 'files' in dd else []
            BUILD_PATH = dd['build_path'] if 'build_path' in dd else './class'
            CLASS_PATH = dd['class_path'] if 'class_path' in dd else BUILD_PATH

            if not slist:
                slist = oss.find('.', "*.java")

            if 'cmds' in dd:
                CMDS = dd['cmds']
            else:
                CMDS = ['compile']


        if opts.makecmd:
            oss.mv(opts.cmdfile, opts.cmdfile + '.bak')
            with open(opts.cmdfile, 'w') as otf:
                slist.extend(oss.find('.', "*.java"))

                ## ensure names are unique
                s = set(slist)
                slist = [a for a in s]

                dd['files'] = slist
                otf.write(yaml.safe_dump(dd))

    else:
        CMDS = ['compile']
        slist = oss.find('.', "*.java")

    if args:
        CMDS = args

    rc = 0
    for cmd in CMDS:
        if rc != 0:
            oss.exit(rc)

        if cmd == 'compile':
            rc = compile(JAVAC, slist, opts.force, opts.readonly)

        elif cmd.startswith('run '):
            c = cmd[4:].strip()
            print(c)
            rc = oss.r(c)

        elif cmd == 'vcs_add':
            addToVcs(VCS_ADD, slist)


    oss.exit(0)
Example #16
0
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)
Example #17
0
def GetRandomSHA(Path):
    #-------------------------------------------------------------------------------
    return oss.SHASum(random.choice(oss.find(Path)))