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
def addBatch(infoaddDict, auto):
    from fup.utils.dbwrap import sql_insertDict
    from fup.helpers.files import saveFilesInfo
    from fup.utils.commun import deletetree  #, cleanPath

    infoaddDict['Responsible'] = 'UNASSIGNED'
    infoaddDict['Proofreader'] = 'UNASSIGNED'
    infoaddDict['ResponsibleStatus'] = 'UNASSIGNED'
    infoaddDict['ProofreaderStatus'] = 'UNASSIGNED'
    infoaddDict['OverallStatus'] = 'UNASSIGNED'

    #print('addbatch: ', infoaddDict)

    #Check files added to this batch
    response = saveFilesInfo(infoaddDict, auto)
    if response == True:
        #infoaddDict['OriginalFilesPath'] = cleanPath(infoaddDict['OriginalFilesPath'])
        return sql_insertDict('followup', infoaddDict)
    else:
        #if new batch error then deletetree else(case new files added) don't
        if auto:
            deletetree(infoaddDict['OriginalFilesPath'])
            return response
        else:  # DEFAULT IS AUTO! (all that is not auto is not taken into processing)
            return response
示例#3
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
示例#4
0
def createAssignedDirFiles(unassignedBatch):
    import os, re, shutil
    from fup.utils.jsoninfo import configInfo, sessionInfo
    from fup.utils.commun import getfilespath_from, deletetree
    config = configInfo()
    session = sessionInfo()
    user = session['current_user_working']
    if re.search('@', user):
        user = user.split('@')[0]

    dir_unassigned = config[
        "path_to_batches_prepfiles"]  #changed from unassigned path to prepfiles path
    dir_assigned = config['path_to_batches_assigned']
    dir_frontend = config['path_to_frontend']
    dir_feli = os.listdir(dir_frontend)
    dir_feli = [f for f in dir_feli if re.search('.xlsm', f)]
    dir_feFile = [f for f in dir_feli if not re.search('BETA', f.upper())]
    dir_bidli = os.listdir(dir_unassigned)

    try:
        for biddir in dir_bidli:
            if re.search(unassignedBatch, biddir):
                #Get the unassigned and assigned folders paths
                opfile_dirunassigned = os.path.join(dir_unassigned, biddir)
                opfile_dirassigned = os.path.join(dir_assigned,
                                                  str(user + '-' + biddir))
                #Make a new directory in the Assigned folder
                os.mkdir(opfile_dirassigned)
                #Copy the FE macro to the folder created
                fepathfile = os.path.join(dir_frontend, dir_feFile[0])
                shutil.copy2(fepathfile, opfile_dirassigned)
                #Create also here the OP FILE folder and copy here the files from unassigned
                opfilepath = os.path.join(opfile_dirassigned, 'OP FILE')
                os.mkdir(opfilepath)
                org_filesli = getfilespath_from(opfile_dirunassigned)
                org_files = [
                    f for f in org_filesli if not re.search('Thumbs.db', f)
                ]
                for file in org_files:
                    shutil.copy2(file, opfilepath)

                #Rename the FE macro
                filesinassigned = os.listdir(opfile_dirassigned)
                fenameold = [
                    f for f in filesinassigned if re.search('.xlsm', f)
                ][0]
                fefileold = os.path.join(opfile_dirassigned, fenameold)
                fenamenew = unassignedBatch + '-' + fenameold
                fefilenew = os.path.join(opfile_dirassigned, fenamenew)
                os.rename(fefileold, fefilenew)
                #delete the dir from prep files folder
                deletetree(os.path.join(dir_unassigned, biddir))

        return True

    except Exception as e:
        print("GOT: ", e)
        return False
示例#5
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)
示例#6
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
示例#7
0
def saveFilesInfo(infoDict, auto):
    import os
    import pandas
    from fup.helpers.files import getfileSizeMtime, matchOriginalinNew, getFileId, originalFilesPaths, checkFileInfo, updateDBforNewFiles
    from fup.utils.dbwrap import sql_insertDict, sql2df
    from fup.utils.commun import deletetree

    path = infoDict['OriginalFilesPath']
    #print("yuhuu ",path)

    newfiles = os.listdir(path)

    orgfilespath = originalFilesPaths(infoDict)
    if isinstance(orgfilespath, str):
        return orgfilespath  #response

    orgfiles = [path.split('\\')[-1] for path in orgfilespath]

    matchedFiles = matchOriginalinNew(orgfiles, newfiles)

    for filepath in orgfilespath:
        fileinfo = getfileSizeMtime(filepath)
        fileinfo['FileID'], fileinfo['FileName'] = getFileId(
            filepath, matchedFiles)
        fileinfo['AddedInBatch'] = infoDict['BatchID']
        responseFileInfo = checkFileInfo(fileinfo)
        #print(filepath)
        if responseFileInfo != True:
            deletetree(path)
            return responseFileInfo

        else:
            if auto:
                pass
            else:
                if sql_insertDict('fileshistory', fileinfo) == False:
                    return False

    return True