def movetobin(tobinli):
    import shutil
    from fup.helpers.batch import batchExists
    from fup.utils.commun import deletetree

    dirsnotmoved = []
    for d in tobinli:
        src = d['source']
        dst = d['destination']
        bid = dst.split("\\")[-1]
        try:
            if batchExists(bid):
                print('movetobin- ', src, dst, bid)
                shutil.move(src, dst)
        except:
            dirsnotmoved.append(d)
            pass
    
    for d in dirsnotmoved:
        #[{'source': 'E:\\working_python\\Followup v0.59\\DC BATCHES IN WORK\\0 NEW\\ASD 300', 'destination': 'E:\\working_python\\Followup v0.59\\bin\\LvHDKI'}]
        src = d['source']
        deletetree(src)

    if len(dirsnotmoved) == 0:
        #print('\nfiles moved to bin')
        return True
    else:
        #print(dirsnotmoved)
        return dirsnotmoved
示例#2
0
def batchInfo(batchid):
    from fup.utils.dbwrap import get_dftable
    from fup.helpers.batch import batchExists
    import pandas

    if batchExists(batchid):
        df = get_dftable('followup')
        df_batchDict = df[df['BatchID'] == batchid].to_dict('list')
        return df_batchDict
    else:
        return False
示例#3
0
def delDirsnotindb():
    import os
    from fup.utils.jsoninfo import configInfo
    from fup.utils.commun import deletetree
    from fup.helpers.batch import batchExists

    config = configInfo()
    unassignedpath = os.path.abspath(config['path_to_batches_unassigned'])
    unassigneddirli = os.listdir(unassignedpath)

    todelDirs = {}
    for batchNameFolder in unassigneddirli:
        bid = batchNameFolder.split('BID_')[-1].replace('_', '')
        if batchNameFolder == '_info.txt':
            continue
        if not batchExists(bid):
            todelDirs[bid] = batchNameFolder

    for kbid, vdirName in todelDirs.items():
        deldir = os.path.join(unassignedpath, vdirName)
        deletetree(deldir)
示例#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
def assignBatchtoUser(batchID, assignedtoProofreader):
    from fup.utils.jsoninfo import sessionInfo
    from fup.utils.commun import current_date
    from fup.helpers.batch import getUnassignedBatch
    from fup.helpers.batchdirs import createAssignedDirFiles
    from fup.models.batch import checkOverallStatus
    from fup.utils.dbwrap import sql_updateDict
    from fup.helpers.batch import batchExists
    from fup.helpers.user import getuserProofreader

    if checkOverallStatus() == True:

        date = current_date()
        userinfo = sessionInfo()
        responsible_user = userinfo["current_user_working"]
        defaultProofreader = getuserProofreader(responsible_user)

        tableName = 'followup'

        updatedict = {
            "BatchID": batchID,
            "Responsible": responsible_user,
            "ResponsibleStatus": "ASSIGNED",
            "Proofreader": defaultProofreader,
            "ProofreaderStatus": "ASSIGNED",
            "ChangesLog": ''
        }
        if defaultProofreader == "UNASSIGNED":
            updatedict["ProofreaderStatus"] = "UNASSIGNED"

        updatedict_fallback = {
            "BatchID": batchID,
            "Responsible": "UNASSIGNED",
            "ResponsibleStatus": "UNASSIGNED",
            "Proofreader": "UNASSIGNED",
            "ProofreaderStatus": "UNASSIGNED",
            "ChangesLog": ''
        }

        colIDName = "BatchID"

        #print(updatedict)
        if (batchID == '' or batchExists(batchID)) and (assignedtoProofreader
                                                        == True):
            unassignedBatch = getUnassignedBatch(batchID, 'ProofreaderStatus')
            updatedict["BatchID"] = unassignedBatch
            updatedict_fallback["BatchID"] = unassignedBatch
        elif (batchID == '' or batchExists(batchID)) and (assignedtoProofreader
                                                          == False):
            unassignedBatch = getUnassignedBatch(batchID, 'ResponsibleStatus')
            updatedict["BatchID"] = unassignedBatch
            updatedict_fallback["BatchID"] = unassignedBatch

        if assignedtoProofreader == True:
            updatedict.pop("Responsible", None)
            updatedict.pop("ResponsibleStatus", None)
            updatedict.pop("ChangesLog", None)
            if sql_updateDict(tableName, updatedict, colIDName) == True:
                checkOverallStatus()
                return True
            else:
                print('1fallback', tableName, updatedict, colIDName)
                sql_updateDict(tableName, updatedict_fallback, colIDName)
                return False

        elif assignedtoProofreader == False:
            loginfo = "ASSIGNED to {} on {}".format(responsible_user, date)
            updatedict["ChangesLog"] = loginfo
            updatedict["StartDate"] = date
            if (sql_updateDict(tableName, updatedict,
                               colIDName)) == True and (createAssignedDirFiles(
                                   updatedict["BatchID"]) == True):
                checkOverallStatus()
                return True
            else:
                print('2fallback', tableName, updatedict, colIDName)
                sql_updateDict(tableName, updatedict_fallback, colIDName)
                return False
    else:
        return False