コード例 #1
0
ファイル: file.py プロジェクト: silentthakar/JigsawPuzzle
def uploadFile(inputFile):

    chunkInfoList, used_origin_credential, used_replication_credential = splitFile(inputFile)

    division_thread_by_account(chunkInfoList, used_origin_credential)

    createMetaData()

    division_thread_to_replicate(used_replication_credential)

    indexOfPoint = inputFile.rfind('.')
    fileName = inputFile[:indexOfPoint]
    log = fileName + " complete"
    googleDrive.write_garbage_log(log)

    createMetaDataForReplicate()
コード例 #2
0
ファイル: file.py プロジェクト: silentthakar/JigsawPuzzle
def uploadGoogledrive(accountSortList, account, flag):

    uploadfilePath = os.getcwd() + "/cache/"
    service = credentials.get_service(account)
    folderID = googleDrive.get_shared_folder_id(service, account)
    two_time = 0

    dt_obj = datetime.now()
    dt_obj = dt_obj.replace(day=dt_obj.day + 7)
    nowDate = datetime.strftime(dt_obj, '%Y_%m_%d')

    daily_folder_id = googleDrive.check_daily_folder_and_get_id(service, account, nowDate, folderID)

    for i in range(0, len(accountSortList)):
        fn1 = accountSortList[i]['chunkName']
        fileName = nowDate + '_' + fn1

        garbage_log = account + ' ' + fileName
        googleDrive.write_garbage_log(garbage_log)

        if os.path.isfile(uploadfilePath+fn1):
            # upload_file(업로드된후 파일명, 파일설명, 파일타입, 실제 올릴 파일경로)
            uploadFile = googleDrive.upload_file(service, daily_folder_id, "%s" % fileName, '', '', uploadfilePath + fn1)

            if type(uploadFile) == 'NoneType':
                 print ("[ERROR ] Failed upload Chunk({0})- '{1}'".format(accountSortList[i]['indexOfChunk']+1, fn1))

            else:
                if flag == "origin":
                    global infoList

                    log = "upload_" + fn1 + '_' + account + "_origin"
                    googleDrive.write_log(log)

                    if accountSortList[i]['origin'][account] == "null":
                        accountSortList[i]['origin'][account] = uploadFile['id']
                        accountSortList[i]['uploadTime'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                        infoList.append(accountSortList[i])

                        print ("[SYSTEM] Stored metadata of original Chunk({0})- '{1}'".format(accountSortList[i]['indexOfChunk']+1, fn1))

                elif flag == "replication":
                    global finished_infoList

                    log = "upload_" + fn1 + '_' + account + "_replication"
                    googleDrive.write_log(log)

                    if accountSortList[i]['replication'][account] == "null":
                        accountSortList[i]['replication'][account] = uploadFile['id']

                        # Delete already uploaded chunk file
                        for key in accountSortList[i]['replication']:
                            if key != account:
                                if accountSortList[i]['replication'][key] != "null":
                                    if fileName == uploadFile['title']:
                                        two_time += 1
                        if two_time == 1:
                            two_time = 0
                            finished_infoList.append(accountSortList[i])
                            print ("[SYSTEM] Stored metadata of replication of Chunk({0})- '{1}'".format(accountSortList[i]['indexOfChunk']+1, fn1))
                            os.remove(uploadfilePath+fn1)
                            print ("[DELETE] Remove already uploaded chunk file - '{0}'".format(fn1))
        else:
            print ("[ERROR ] Failed upload Chunk({0})- '{1}'".format(accountSortList[i]['indexOfChunk']+1, fn1))