Esempio n. 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
Esempio n. 2
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