Beispiel #1
0
def recreatetags(srrlist, srrfile, args):
    listdir = os.listdir()
    keeplist = []
    srsfiles = []

    for f in sorted(srrlist[0]):
        if re.search(r'\.srs$', f, re.IGNORECASE) is None:
            keeplist.append(f)
            continue

        srsfiles.append(f)

        srs = SRS(filename=f, binary=args['srs_bin'])
        srslist = srs.listfiles()
        keeplist.append(srslist[0])
        inputfile = os.path.join(os.getcwd(), srslist[0])
        if '/' in srslist[0]:
            outputdir = srslist[0].split('/')[0]
        else:
            outputdir = os.getcwd()

        if not os.path.exists(inputfile):
            fr = r'^' + srslist[0].split('/')[-1].split('-')[0] + r'[-_ ].*\.' + srslist[0].split('.')[-1] + r'$'
            for f in listdir:
                if f == inputfile.split('/')[-1] or re.search(fr, f, re.IGNORECASE) is not None:
                    try:
                        shutil.copy(f, inputfile)
                    except:
                        if len(str(sys.exc_info()[1])) > 0:
                            print(sys.exc_info()[1])
                        return False

                    if srs.recreate(inputfile, output=outputdir) == True:
                        break
                    else:
                        try:
                            os.unlink(inputfile)
                        except:
                            if len(str(sys.exc_info()[1])) > 0:
                                print(sys.exc_info()[1])
                            return False

        elif srs.recreate(inputfile, output=outputdir) == False:
            return False

        if not os.path.isfile(inputfile):
            return False

    if len(keeplist) > 0 and len(srsfiles) > 0 and deleteothers(keeplist, srrfile) == False:
        return False
Beispiel #2
0
def recreatetags(srrlist, srrfile, args):
    listdir = os.listdir(os.getcwd())
    keeplist = []
    srsfiles = []

    for srsfile in sorted(srrlist[0]):
        if re.search(r'\.srs$', srsfile, re.IGNORECASE) is None:
            keeplist.append(srsfile)
            continue

        srsfiles.append(srsfile)

        srs = SRS(filename=srsfile, binary=args['srs_bin'])
        srsinfo = srs.info()
        if srsinfo == False:
            continue
        keeplist.append(srsinfo[0])

        if '/' in srsfile:
            outdir = os.path.join(os.getcwd(), srsfile.split('/')[0])
            if not os.path.isdir(outdir):
                try:
                    os.mkdir(outdir)
                except:
                    if len(str(sys.exc_info()[1])) > 0:
                        print sys.exc_info()[1]
                    return False
        else:
            outdir = os.getcwd()

        infile = None
        if os.path.isfile(os.path.join(outdir, srsinfo[0])):
            infile = os.path.join(outdir, srsinfo[0])
        elif os.path.isfile(os.path.join(os.getcwd(), srsinfo[0])):
            infile = os.path.join(os.getcwd(), srsinfo[0])
        else:
            print 'Input file not found: %s' % (srsinfo[0])

        if infile is None:
            infile = os.path.join(outdir, srsinfo[0])
            fr = r'^' + srsinfo[0].split('/')[-1].split('-')[0] + r'[-_ ].*\.' + srsinfo[0].split('.')[-1] + r'$'
            for srsfile in listdir:
                if srsfile == infile.split(os.sep)[-1] or re.search(fr, srsfile, re.IGNORECASE) is not None:
                    try:
                        shutil.copy(srsfile, infile)
                    except:
                        if len(str(sys.exc_info()[1])) > 0:
                            print sys.exc_info()[1]
                        return False

                    if srs.recreate(infile, outdir=outdir) == True:
                        break
                    else:
                        try:
                            os.unlink(infile)
                        except:
                            if len(str(sys.exc_info()[1])) > 0:
                                print sys.exc_info()[1]
                            return False

        elif srs.recreate(infile, outdir=outdir) == False:
            return False

        if infile == os.path.join(os.getcwd(), srsinfo[0]) and outdir != os.getcwd():
            try:
                os.unlink(infile)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

    if sfvverify(args, opts='-r') == False:
        return False

    if len(keeplist) > 0 and len(srsfiles) > 0 and deleteothers(keeplist, srrfile) == False:
        return False

    return None
Beispiel #3
0
def recreatesample(srr, srrlist, args):
    for f in srrlist[0]:
        if re.search(r'\.srs$', f, re.IGNORECASE) is None:
            continue

        srsfile = f
        if not os.path.isfile(srsfile) and os.path.isfile(os.path.basename(f)):
            srsfile = os.path.basename(f)

        if not os.path.isfile(srsfile):
            return False

        srs = SRS(filename=srsfile, binary=args['srs_bin'])
        srsinfo = srs.info()
        if srsinfo == False:
            continue

        defaultdir = os.path.join(os.getcwd(), 'Sample')
        if '/' in srsfile:
            sampledir = os.path.join(os.getcwd(), srsfile.split('/')[0])
        else:
            sampledir = defaultdir

        if not os.path.isdir(sampledir):
            try:
                os.mkdir(sampledir)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        if sampledir != defaultdir and os.path.isdir(defaultdir):
            try:
                for s in os.listdir(defaultdir):
                    shutil.copy(os.path.join(defaultdir, s), sampledir)
                shutil.rmtree(defaultdir)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        if os.path.isfile(os.path.join(os.getcwd(), srsinfo[0])):
            try:
                shutil.move(os.path.join(os.getcwd(), srsinfo[0]), sampledir)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        sample = None
        if os.path.isfile(os.path.join(sampledir, srsinfo[0])):
            sample = os.path.join(sampledir, srsinfo[0])

        if sample is not None:
            print '\'%s\' found, sample exists.' % (os.path.dirname(sample).split(os.sep)[-1] + os.sep + sample.split(os.sep)[-1])

            if crc(sample) == srsinfo[2] and args['force'] == False:
                try:
                    os.unlink(srsfile)
                except:
                    if len(str(sys.exc_info()[1])) > 0:
                        print sys.exc_info()[1]
                    return False

                continue

            try:
                os.unlink(sample)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        srsinput = None
        if os.path.isfile(srrlist[1][0]):
            srsinput = srrlist[1][0]
        elif os.path.isfile(srrlist[1][0].split('/')[-1]):
            srsinput = srrlist[1][0].split('/')[-1]

        if srsinput is not None:
            if srs.recreate(infile=srsinput, outdir=sampledir + os.sep) == False:
                return False

        try:
            os.unlink(srsfile)
        except:
            if len(str(sys.exc_info()[1])) > 0:
                print sys.exc_info()[1]
            return False

    return None
Beispiel #4
0
def recreatesample(srr, srrlist, args):
    sampledir = os.path.join(os.getcwd(), 'Sample')

    for f in srrlist[0]:
        if re.search(r'\.srs$', f, re.IGNORECASE) is None:
            continue

        srs = SRS(filename=f, binary=args['srs_bin'])
        srslist = srs.listfiles()

        sample = None

        if os.path.isfile(os.path.join(os.getcwd(), srslist[0])):
            sample = os.path.join(os.getcwd(), srslist[0])
            if not os.path.isdir(sampledir):
                try:
                    os.mkdir(sampledir)
                except:
                    if len(str(sys.exc_info()[1])) > 0:
                        print(sys.exc_info()[1])
                    return False
            try:
                shutil.move(sample, sampledir)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print(sys.exc_info()[1])
                return False

        if os.path.isfile(os.path.join(os.getcwd(), 'Sample', srslist[0])):
            sample = os.path.join('Sample', srslist[0])

        if sample is not None:
            print('%r found, sample exists.' % (sample))
            if args['force'] == False:
                try:
                    os.unlink(f)
                except:
                    if len(str(sys.exc_info()[1])) > 0:
                        print(sys.exc_info()[1])
                    return False

                continue

            try:
                os.unlink(sample)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print(sys.exc_info()[1])
                return False

        srsinput = None
        if os.path.isfile(srrlist[1][0]):
            srsinput = srrlist[1][0]
        elif os.path.isfile(srrlist[1][0].split('/')[-1]):
            srsinput = srrlist[1][0].split('/')[-1]

        if srsinput is not None:
            if srs.recreate(input=srsinput) == False:
                return False

        try:
            os.unlink(f)
        except:
            if len(str(sys.exc_info()[1])) > 0:
                print(sys.exc_info()[1])
            return False
Beispiel #5
0
def recreatetags(srrlist, srrfile, args):
    listdir = os.listdir(os.getcwd())
    keeplist = []
    srsfiles = []

    for srsfile in sorted(srrlist[0]):
        if re.search(r'\.srs$', srsfile, re.IGNORECASE) is None:
            keeplist.append(srsfile)
            continue

        srsfiles.append(srsfile)

        srs = SRS(filename=srsfile, binary=args['srs_bin'])
        srsinfo = srs.info()
        if srsinfo == False:
            continue
        keeplist.append(srsinfo[0])

        if '/' in srsfile:
            outdir = os.path.join(os.getcwd(), srsfile.split('/')[0])
            if not os.path.isdir(outdir):
                try:
                    os.mkdir(outdir)
                except:
                    if len(str(sys.exc_info()[1])) > 0:
                        print sys.exc_info()[1]
                    return False
        else:
            outdir = os.getcwd()

        infile = None
        if os.path.isfile(os.path.join(outdir, srsinfo[0])):
            infile = os.path.join(outdir, srsinfo[0])
        elif os.path.isfile(os.path.join(os.getcwd(), srsinfo[0])):
            infile = os.path.join(os.getcwd(), srsinfo[0])
        else:
            print 'Input file not found: %s' % (srsinfo[0])

        if infile is None:
            infile = os.path.join(outdir, srsinfo[0])
            fr = r'^' + srsinfo[0].split('/')[-1].split(
                '-')[0] + r'[-_ ].*\.' + srsinfo[0].split('.')[-1] + r'$'
            for srsfile in listdir:
                if srsfile == infile.split(os.sep)[-1] or re.search(
                        fr, srsfile, re.IGNORECASE) is not None:
                    try:
                        shutil.copy(srsfile, infile)
                    except:
                        if len(str(sys.exc_info()[1])) > 0:
                            print sys.exc_info()[1]
                        return False

                    if srs.recreate(infile, outdir=outdir) == True:
                        break
                    else:
                        try:
                            os.unlink(infile)
                        except:
                            if len(str(sys.exc_info()[1])) > 0:
                                print sys.exc_info()[1]
                            return False

        elif srs.recreate(infile, outdir=outdir) == False:
            return False

        if infile == os.path.join(os.getcwd(),
                                  srsinfo[0]) and outdir != os.getcwd():
            try:
                os.unlink(infile)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

    if sfvverify(args, opts='-r') == False:
        return False

    if len(keeplist) > 0 and len(srsfiles) > 0 and deleteothers(
            keeplist, srrfile) == False:
        return False

    return None
Beispiel #6
0
def recreatesample(srr, srrlist, args):
    for f in srrlist[0]:
        if re.search(r'\.srs$', f, re.IGNORECASE) is None:
            continue

        srsfile = f
        if not os.path.isfile(srsfile) and os.path.isfile(os.path.basename(f)):
            srsfile = os.path.basename(f)

        if not os.path.isfile(srsfile):
            return False

        srs = SRS(filename=srsfile, binary=args['srs_bin'])
        srsinfo = srs.info()
        if srsinfo == False:
            continue

        defaultdir = os.path.join(os.getcwd(), 'Sample')
        if '/' in srsfile:
            sampledir = os.path.join(os.getcwd(), srsfile.split('/')[0])
        else:
            sampledir = defaultdir

        if not os.path.isdir(sampledir):
            try:
                os.mkdir(sampledir)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        if sampledir != defaultdir and os.path.isdir(defaultdir):
            try:
                for s in os.listdir(defaultdir):
                    shutil.copy(os.path.join(defaultdir, s), sampledir)
                shutil.rmtree(defaultdir)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        if os.path.isfile(os.path.join(os.getcwd(), srsinfo[0])):
            try:
                shutil.move(os.path.join(os.getcwd(), srsinfo[0]), sampledir)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        sample = None
        if os.path.isfile(os.path.join(sampledir, srsinfo[0])):
            sample = os.path.join(sampledir, srsinfo[0])

        if sample is not None:
            print '\'%s\' found, sample exists.' % (
                os.path.dirname(sample).split(os.sep)[-1] + os.sep +
                sample.split(os.sep)[-1])

            if crc(sample) == srsinfo[2] and args['force'] == False:
                try:
                    os.unlink(srsfile)
                except:
                    if len(str(sys.exc_info()[1])) > 0:
                        print sys.exc_info()[1]
                    return False

                continue

            try:
                os.unlink(sample)
            except:
                if len(str(sys.exc_info()[1])) > 0:
                    print sys.exc_info()[1]
                return False

        srsinput = None
        if os.path.isfile(srrlist[1][0]):
            srsinput = srrlist[1][0]
        elif os.path.isfile(srrlist[1][0].split('/')[-1]):
            srsinput = srrlist[1][0].split('/')[-1]

        if srsinput is not None:
            if srs.recreate(infile=srsinput,
                            outdir=sampledir + os.sep) == False:
                return False

        try:
            os.unlink(srsfile)
        except:
            if len(str(sys.exc_info()[1])) > 0:
                print sys.exc_info()[1]
            return False

    return None