def move_deprecate_folders(dest, co_folder): # get the deprecated folders folders = system_operations.create_list_of_folders(dest) try: folders.remove(OLD_VERSIONS_DIR) except: pass folders = [str(f) for f in map(int, folders) if f > int(co_folder)] folder_id = 0 # create a deprecated folder if folders: # create a unique hash file folder_id = hashlib.sha1() folder_id.update(str(time.time())) folder_id = folder_id.hexdigest()[:15] deprecated_folder = dest + '/' + OLD_VERSIONS_DIR + "/" + folder_id system_operations.creating_dir_tree(deprecated_folder) # move deprecated folders for folder in folders: source_folder = dest + "/" + folder dest_folder = deprecated_folder + '/' + folder system_operations.moving_dir(source_folder, dest_folder) return folder_id
def copy_files(source, dest): # Verify whether workplace folder exists if not os.path.exists(source): print("There is no working file (set to be '%s'). Try again." %source) sys.exit(0) # create the folder for the new snapshot next_snapshot_number = next_snapshot(dest) lastest_snapshot = dest + '/' + next_snapshot_number + '/' system_operations.creating_dir_tree(lastest_snapshot) # get the the files list from the source (the workplace folder) files = system_operations.create_list_of_files(source) message = "Creating a snapshot " + next_snapshot_number + "... " pb = progress_bar.ProgressBar(message) # copy the files to the snapshot folder for i,f in enumerate(files): pb.calculateAndUpdate(i+1, len(files)) contend_file = source + '/' + f backup_file = lastest_snapshot + f system_operations.copying_file(contend_file, backup_file) if len(files) < 50: # show some progress bar :) time.sleep(0.02) print("\nDone!\n") # return the snapshot value to be updated in the HEAD return next_snapshot_number
def copy_files(source, dest): # Verify whether workplace folder exists if not os.path.exists(source): print("There is no working file (set to be '%s'). Try again." % source) sys.exit(0) # create the folder for the new snapshot next_snapshot_number = next_snapshot(dest) lastest_snapshot = dest + '/' + next_snapshot_number + '/' system_operations.creating_dir_tree(lastest_snapshot) # get the the files list from the source (the workplace folder) files = system_operations.create_list_of_files(source) message = "Creating a snapshot " + next_snapshot_number + "... " pb = progress_bar.ProgressBar(message) # copy the files to the snapshot folder for i, f in enumerate(files): pb.calculateAndUpdate(i + 1, len(files)) contend_file = source + '/' + f backup_file = lastest_snapshot + f system_operations.copying_file(contend_file, backup_file) if len(files) < 50: # show some progress bar :) time.sleep(0.02) print("\nDone!\n") # return the snapshot value to be updated in the HEAD return next_snapshot_number
def next_snapshot(dest): # Verify whether snapshot (.b3g) folder exists system_operations.creating_dir_tree(dest) # get the folders in the backup and solder folders = system_operations.create_list_of_folders(dest) or ['0'] try: folders.remove(OLD_VERSIONS_DIR) except: pass folders = map(int, folders) lastest_snapshot = max(folders) + 1 return str(lastest_snapshot)
def do_moving(workfolder, checkoutfolder): # get the files from the snapshot files = system_operations.create_list_of_files(checkoutfolder) pb = progress_bar.ProgressBar("Checking out " + checkoutfolder + "...") # TODOl cleaning working directory, so we get the snapshot right # TODO: this must die!!! use the diff function system_operations.moving_dir(workfolder + "/" + BACKUP_DIR, BACKUP_DIR) system_operations.removing_dir_tree(workfolder) system_operations.creating_dir_tree(workfolder) system_operations.moving_dir(BACKUP_DIR, workfolder) # copying the snapshot to the work folder for i, file in enumerate(files): pb.calculateAndUpdate(i + 1, len(files)) backup_file = checkoutfolder + '/' + file system_operations.copying_file(backup_file, workfolder) time.sleep(0.02)
def test_settingup(self): assert(False) system_operations.creating_dir_tree(CONTEND_DIR) system_operations.creating_file(CONTEND_DIR + "/test.txt" )
def test_six(self): system_operations.creating_dir_tree(DIR_TO_CREATE) assert(os.path.exists(DIR_TO_CREATE))