コード例 #1
0
def unassignedtoPrepfiles():
    #Copy batches from UNASSIGNED to PREPARED FILES
    import re, os, shutil
    from fup.utils.jsoninfo import configInfo
    from fup.utils.commun import copytree

    config = configInfo()

    unassignedpath = os.path.abspath(config['path_to_batches_unassigned'])
    prepfilespath = os.path.abspath(config['path_to_batches_prepfiles'])

    unassigneddirli = os.listdir(unassignedpath)

    for folder in unassigneddirli:
        src = os.path.join(unassignedpath, folder)
        if re.search("Please check these Batches.txt", src):
            continue  #skip
        dst = os.path.join(prepfilespath, folder)
        try:
            os.mkdir(dst)
            copytree(src, dst)
        except:  #copy new files added to the batch
            src_filesli = os.listdir(src)
            dst_fileli = os.listdir(dst)
            if len(src_filesli) > len(dst_fileli):
                for srcFile in src_filesli:
                    s = os.path.join(src, srcFile)
                    d = os.path.join(dst, srcFile)
                    try:
                        shutil.copy2(s, d)
                    except:
                        pass
コード例 #2
0
def moveDirName(dirName, cfg_olddir, cfg_newdir):
    #Move a folder from one path to another, delete the old one
    import os, re, shutil
    from fup.utils.commun import copytree, deletetree
    from fup.utils.jsoninfo import configInfo

    try:
        config = configInfo()
        olddir = config[cfg_olddir]
        newdir = config[cfg_newdir]

        dirtobeMoved = os.listdir(olddir)
        dir_bidtbMoved = [d for d in dirtobeMoved if re.search(dirName, d)]

        pathOld = os.path.join(olddir, dir_bidtbMoved[0])

        pathNew = os.path.join(newdir, dir_bidtbMoved[0])

        src, dst = pathOld, pathNew
        copytree(src, dst, symlinks=False, ignore=None)

        deletetree(pathOld)
        return True
    except:
        return False
コード例 #3
0
def mergeDirBatches(batchidstrli):
    import os, re, shutil, time
    from fup.utils.commun import copytree, generateID, listifyString
    from fup.utils.jsoninfo import configInfo, sessionInfo
    config = configInfo()
    session = sessionInfo()
    try:
        user = session['current_user_working']
        if re.search('@', user):
            user = user.split('@')[0]

        batchidli = listifyString(batchidstrli)

        dir_assigned = config['path_to_batches_assigned']
        dirs_assigned = os.listdir(dir_assigned)

        #Make a dir for the merged batches
        mergedID = generateID()
        mergeddirpath = os.path.join(
            dir_assigned, '{}-___ A___ BID_{}'.format(user, mergedID))
        os.mkdir(mergeddirpath)

        #Get names of the folders from Assigned folder by checking the BID
        dirstomergeli = []
        for batchid in batchidli:
            dir_bidAssigned = [
                d for d in dirs_assigned if re.search(batchid, d)
            ]
            dirstomergeli.append(dir_bidAssigned[0])

        #Copy contents of the old batches into the new created merged folder
        for folderName in dirstomergeli:
            assignedPathOld = os.path.join(dir_assigned, folderName)
            src, dst = assignedPathOld, mergeddirpath
            copytree(src, dst, symlinks=False, ignore=None)
            files_not_deleted = True
            while files_not_deleted:
                try:
                    shutil.rmtree(assignedPathOld)  #delete folders
                    files_not_deleted = False
                except:
                    print("Please close file(s) open in folder {}".format(
                        assignedPathOld))
                    time.sleep(2)

        mergedInfodict = {
            'mergedID': mergedID,
            'mergeddirpath': mergeddirpath,
            'batchidli': batchidli
        }
        return mergedInfodict
    except Exception as e:
        print('mergeDirBatches/helpers Got :', e)
        return False
コード例 #4
0
def createSplitDirs(splitFactor, batchid):
    import os, re, shutil
    from fup.utils.commun import copytree, deletetree, generateID
    from fup.utils.jsoninfo import configInfo
    from fup.helpers.batch import batchExists
    config = configInfo()

    if batchExists(batchid) == False:
        return False

    #Get path to ASSIGNED and filer by BID
    dir_assigned = config['path_to_batches_assigned']
    dirs_assigned = os.listdir(dir_assigned)
    dir_bidAssigned = [d for d in dirs_assigned if re.search(batchid, d)]
    if len(dir_bidAssigned) == 0:
        return False

    #Copy the main directory in the range of the splitFactor
    assignedPathOld = os.path.join(dir_assigned, dir_bidAssigned[0])

    oldDirName = dir_bidAssigned[0]
    respNameAC = ' '.join(oldDirName.split(' ')[0:-1])

    newSplitpathsd = {}
    idli = []
    for splitedID in range(splitFactor):
        newid = generateID()
        newdirName = respNameAC + ' BID_' + newid
        assignedPathNew = os.path.join(dir_assigned, newdirName)
        src, dst = assignedPathOld, assignedPathNew
        copytree(src, dst, symlinks=False, ignore=None)
        newSplitpathsd[newdirName] = assignedPathNew
        idli.append(newid)

    newSplitpathsd['newids'] = ', '.join(idli)
    newSplitpathsd['oldid'] = batchid

    deletetree(assignedPathOld)

    return newSplitpathsd