Exemplo n.º 1
0
def mkdir(dirlist, execute, quiet):
	for dir in dirlist:
		if execute:
		 	os.makedirs(dir)

		else:
		 	print_cli("dry-run: mkdir -p " + dir + "\n", quiet)
Exemplo n.º 2
0
def cp(ops_list, execute, force, quiet):

	check_writable(ops_list)

	for pair in ops_list:
		if execute:
			shutil.copyfile(pair[0], pair[1])
		else:
			print_cli("dry-run: cp" + pair[0] + " " + pair[1] + "\n", quiet)
Exemplo n.º 3
0
def ln(ops_list, execute, force, quiet):

	check_writable(ops_list)

	for pair in ops_list:
		if execute:
			try:
				os.symlink(pair[0], pair[1])
			except OSError:
				if force:
					os.remove(pair[1])
					os.symlink(pair[0], pair[1])
		else:
			print_cli("dry-run: ln -s " + pair[0] + " " + pair[1] + "\n", quiet)
Exemplo n.º 4
0
def builder(operation, original_seqlist, modified_seqlist, in_dir, out_dir, create_dirs=False, force=False, skip=False, quiet=False, execute=False):
	""" construct the to and from filelists, check for conflicts, prepare directories and do the move/link/copy etc... """
	
	ops_list = []

	for pair in zip (original_seqlist, modified_seqlist):
		original = pair[0] if pair[0] else pair[1]
		modified = pair[1]
		ops_list += get_ops(original, modified, in_dir, out_dir)

	ops_list, missing_paths, missing_source_files, conflicting_files = check_conflicts(ops_list)

	if missing_source_files:
		report("Warning, missing following source files:", "missing: ", missing_source_files, quiet)
		if not skip:
			raise OSError("missing files")

	if conflicting_files:
		if operation == mv: ops_list, conflicting_files = reorder_ops(ops_list, conflicting_files)
		if conflicting_files:
			report("Warning, following files already exist", "file exists: ", conflicting_files, quiet)
			if not force:
				raise OSError("files exist")

	if missing_paths:
		missing_paths = sorted(set(missing_paths)) # remove duplicate mentions of the same paths

		if not create_dirs:
			report("Warning, following paths should be created", "missing path: ", missing_paths, quiet)
			raise OSError("target paths missing")
		else:
			mkdir(missing_paths, execute, quiet)

	operation(ops_list, execute, force, quiet) # rfbuild passes in variable pointing to the actual function.
	if ops_list:
		if not execute:
			print_cli("run with --execute to actually run these operations\n", quiet)
	else:
		print_cli("nothing to do\n", quiet)
Exemplo n.º 5
0
def report(error, perline, filelist, quiet):
	""" print whole bunch of lines with custom message, checking quiet in here bit odd """
	if not quiet:
		print_cli(error + '\n')
		for filename in filelist:
			print_cli("  " + perline + filename + '\n')