def find_all_links(filename, include_target=False): """Dereferences symlinks from a path. If include_target is True, this also returns the real path of the final target. Example: / a -> b b g -> c c -> ../a/d d e -> /f f >>> find_all_links('/a/g/e', True) ['/a', '/b/c', '/b/g', '/b/d/e', '/f'] """ files = set() filename = Path(filename) assert filename.absolute() path = find_all_links_recursive(filename, files) files = list(files) if include_target: files.append(path) return files
def run(self, files): reprounzip.common.record_usage(upload_files=len(files)) inputs_outputs = self.get_config().inputs_outputs # No argument: list all the input files and exit if not files: print("Input files:") for input_name in sorted(n for n, f in iteritems(inputs_outputs) if f.read_runs): assigned = self.input_files.get(input_name) if assigned is None: assigned = "(original)" elif assigned is False: assigned = "(not created)" elif assigned is True: assigned = "(generated)" else: assert isinstance(assigned, (bytes, unicode_)) print(" %s: %s" % (input_name, assigned)) return self.prepare_upload(files) try: # Upload files for filespec in files: filespec_split = filespec.rsplit(':', 1) if len(filespec_split) != 2: logging.critical("Invalid file specification: %r", filespec) sys.exit(1) local_path, input_name = filespec_split if input_name.startswith('/'): input_path = PosixPath(input_name) else: try: input_path = inputs_outputs[input_name].path except KeyError: logging.critical("Invalid input file: %r", input_name) sys.exit(1) temp = None if not local_path: # Restore original file from pack logging.debug("Restoring input file %s", input_path) fd, temp = Path.tempfile(prefix='reprozip_input_') os.close(fd) local_path = self.extract_original_input( input_name, input_path, temp) if local_path is None: temp.remove() logging.warning( "No original packed, can't restore " "input file %s", input_name) continue else: local_path = Path(local_path) logging.debug("Uploading file %s to %s", local_path, input_path) if not local_path.exists(): logging.critical("Local file %s doesn't exist", local_path) sys.exit(1) self.upload_file(local_path, input_path) if temp is not None: temp.remove() self.input_files.pop(input_name, None) else: self.input_files[input_name] = local_path.absolute().path finally: self.finalize()
def run(self, files): reprounzip.common.record_usage(upload_files=len(files)) runs = self.get_runs_from_config() # No argument: list all the input files and exit if not files: print("Input files:") for i, run in enumerate(runs): if len(runs) > 1: print(" Run %d:" % i) for input_name in run['input_files']: if self.input_files.get(input_name) is not None: assigned = PosixPath(self.input_files[input_name]) else: assigned = "(original)" print(" %s: %s" % (input_name, assigned)) return self.prepare_upload(files) # Get the path of each input file all_input_files = {} for run in runs: all_input_files.update(run['input_files']) try: # Upload files for filespec in files: filespec_split = filespec.rsplit(':', 1) if len(filespec_split) != 2: logging.critical("Invalid file specification: %r", filespec) sys.exit(1) local_path, input_name = filespec_split try: input_path = PosixPath(all_input_files[input_name]) except KeyError: logging.critical("Invalid input file: %r", input_name) sys.exit(1) temp = None if not local_path: # Restore original file from pack logging.debug("Restoring input file %s", input_path) fd, temp = Path.tempfile(prefix='reprozip_input_') os.close(fd) local_path = self.extract_original_input( input_name, input_path, temp) else: local_path = Path(local_path) logging.debug("Uploading file %s to %s", local_path, input_path) if not local_path.exists(): logging.critical("Local file %s doesn't exist", local_path) sys.exit(1) self.upload_file(local_path, input_path) if temp is not None: temp.remove() self.input_files.pop(input_name, None) else: self.input_files[input_name] = local_path.absolute().path finally: self.finalize()
def run(self, files): reprounzip.common.record_usage(upload_files=len(files)) input_files = dict( (n, f.path) for n, f in iteritems(self.get_config().inputs_outputs) if f.read_runs) # No argument: list all the input files and exit if not files: print("Input files:") for input_name in input_files: if self.input_files.get(input_name) is not None: assigned = self.input_files[input_name] else: assigned = "(original)" print(" %s: %s" % (input_name, assigned)) return self.prepare_upload(files) try: # Upload files for filespec in files: filespec_split = filespec.rsplit(':', 1) if len(filespec_split) != 2: logging.critical("Invalid file specification: %r", filespec) sys.exit(1) local_path, input_name = filespec_split try: input_path = input_files[input_name] except KeyError: logging.critical("Invalid input file: %r", input_name) sys.exit(1) temp = None if not local_path: # Restore original file from pack logging.debug("Restoring input file %s", input_path) fd, temp = Path.tempfile(prefix='reprozip_input_') os.close(fd) local_path = self.extract_original_input(input_name, input_path, temp) if local_path is None: temp.remove() logging.warning("No original packed, can't restore " "input file %s", input_name) continue else: local_path = Path(local_path) logging.debug("Uploading file %s to %s", local_path, input_path) if not local_path.exists(): logging.critical("Local file %s doesn't exist", local_path) sys.exit(1) self.upload_file(local_path, input_path) if temp is not None: temp.remove() self.input_files.pop(input_name, None) else: self.input_files[input_name] = local_path.absolute().path finally: self.finalize()
def run(self, files): runs = self.get_runs_from_config() # No argument: list all the input files and exit if not files: print("Input files:") for i, run in enumerate(runs): if len(runs) > 1: print(" Run %d:" % i) for input_name in run['input_files']: if self.input_files.get(input_name) is not None: assigned = PosixPath(self.input_files[input_name]) else: assigned = "(original)" print(" %s: %s" % (input_name, assigned)) return self.prepare_upload(files) # Get the path of each input file all_input_files = {} for run in runs: all_input_files.update(run['input_files']) try: # Upload files for filespec in files: filespec_split = filespec.rsplit(':', 1) if len(filespec_split) != 2: logging.critical("Invalid file specification: %r", filespec) sys.exit(1) local_path, input_name = filespec_split try: input_path = PosixPath(all_input_files[input_name]) except KeyError: logging.critical("Invalid input file: %r", input_name) sys.exit(1) temp = None if not local_path: # Restore original file from pack logging.debug("Restoring input file %s", input_path) fd, temp = Path.tempfile(prefix='reprozip_input_') os.close(fd) local_path = self.extract_original_input(input_name, input_path, temp) else: local_path = Path(local_path) logging.debug("Uploading file %s to %s", local_path, input_path) if not local_path.exists(): logging.critical("Local file %s doesn't exist", local_path) sys.exit(1) self.upload_file(local_path, input_path) if temp is not None: temp.remove() del self.input_files[input_name] else: self.input_files[input_name] = local_path.absolute().path finally: self.finalize()