def get_build_dir(): build_path = Path(build_config.build_dir) if build_path.is_absolute(): return build_path.joinpath(build_config.name) else: return Path(working_path).joinpath(build_config.build_dir, build_config.name)
def _absolute_path(cls, file_path, cwd): # return the absolute path, relative to a specific working directory (cwd) file_path = Path(file_path) if file_path.is_absolute(): return file_path.as_posix() # Convert to absolute and squash 'path/../folder' return os.path.abspath((Path(cwd).absolute() / file_path).as_posix())
def get_data_path(path): """Prefix the given path with the path to data volumes. Resolves a (Kard-relative or absolute) given data_path or goes with the default "<kard>/data".""" data_path = Path(self.kard.meta.get('data_path', 'data')) if data_path.is_absolute(): return str(data_path / path) return str(self.kard_folder_path / self.kard.name / data_path / path)
def get_options(): mc_path_default = str(Path.home() / "multichain") parser = ArgumentParser( description="Add clang flags to GN compiler config file") parser.add_argument("-v", "--verbose", action="store_true", help="write debug messages to log") parser.add_argument("-m", "--multichain", metavar="DIR", default=mc_path_default, help="MultiChain path prefix (default: %(default)s)") parser.add_argument( "-i", "--inplace", metavar="EXT", action="store", const=".bak", nargs="?", default="", help= "replace file (default: '%(const)s' if given, output to stdout if not)" ) parser.add_argument("-c", "--config", metavar="FILE", default="clang_fix.config", help="configuration file name (default: %(default)s)") options = parser.parse_args() if options.verbose: logger.setLevel(logging.DEBUG) if not Path(options.multichain).exists(): parser.error("{!r}: MultiChain path does not exist".format( options.multichain)) config_file = Path(options.config) if not config_file.is_absolute(): options.config = str(Path(__file__).parent / config_file) logger.info("{} - {}".format(module_name, parser.description)) logger.info(" MultiChain: {!r}".format(options.multichain)) logger.info(" In-place: {!r}".format(options.inplace)) logger.info(" Config: {!r}".format(options.config)) return options
def copy_project_file(dir_list): for d in dir_list: for f in d.files: if f[1] == "": f[1] = f[0] src_path = Path(d.src_dir) if src_path.is_absolute(): src = src_path.joinpath(f[0]) else: src = working_path.joinpath(d.src_dir, f[0]) dest = build_dir.joinpath(f[1]) print("copy {} to {}".format(src, dest)) try: ign = d.ignores except AttributeError: ign = None fsutils.copy(src, dest, ign)
def _resolve_attachment_path(self, path): """Find attachment file or raise MailmergeError.""" # Error on empty path if not path.strip(): raise MailmergeError("Empty attachment header.") # Create a Path object and handle home directory (tilde ~) notation path = Path(path.strip()) path = path.expanduser() # Relative paths are relative to the template's parent dir if not path.is_absolute(): path = self.template_path.parent / path # Resolve any symlinks path = path.resolve() # Check that the attachment exists if not path.exists(): raise MailmergeError("Attachment not found: {}".format(path)) return path
def get_dist_dir(): dist_path = Path(build_config.dist_dir) if dist_path.is_absolute(): return dist_path return Path(working_path).joinpath(build_config.dist_dir)
# or make sure it's less than the number of allowed characters if cfg_metric == Metric.MIX: if cfg_mix_threshold < 1: cfg_mix_threshold = round(cfg_mix_threshold * len(cfg_ascii_w)) cfg_mix_threshold = np.clip(round(cfg_mix_threshold), 1, len(cfg_ascii_w) - 1) logger.debug( f"Set MIX threshold at the best {cfg_mix_threshold} picks.") """ --------------------Files-------------------- """ originals = [] filenames = [] # Test existence of files try: if not cfg_img_path.is_absolute(): input_path = Path(cwd, "image_in", cfg_img_path) else: input_path = cfg_img_path # Files if input_path.is_file(): add_new_image_from_file(input_path) # Directories elif input_path.is_dir(): for img in input_path.glob("*"): add_new_image_from_file(img) else: logger.error("Could not resolve path.") raise OSError except OSError: