def command(opts, parser, extra_arg_groups=None): from rez.config import config from rez.utils.yaml import dump_yaml if opts.search_list: for filepath in config.filepaths: print filepath return if opts.source_list: for filepath in config.sourced_filepaths: print filepath return data = config.data if opts.FIELD: keys = opts.FIELD.split('.') while keys: key = keys[0] keys = keys[1:] try: data = data[key] except KeyError: raise ValueError("no such setting: %r" % opts.FIELD) if isinstance(data, (dict, list)): txt = dump_yaml(data).strip() print txt else: print data
def command(opts, parser, extra_arg_groups=None): from rez.config import config from rez.utils.yaml import dump_yaml from rez.utils.data_utils import convert_json_safe if opts.search_list: for filepath in config.filepaths: print(filepath) return if opts.source_list: for filepath in config.sourced_filepaths: print(filepath) return data = config.data if opts.FIELD: keys = opts.FIELD.split('.') while keys: key = keys[0] keys = keys[1:] try: data = data[key] except KeyError: raise ValueError("no such setting: %r" % opts.FIELD) if isinstance(data, (dict, list)): if opts.json: txt = json.dumps(convert_json_safe(data)) else: txt = dump_yaml(data) print(txt.strip()) else: print(data)
def build(self, context, variant, build_path, install_path, install=False, build_type=BuildType.local): # communicate args to bez by placing in a file doc = dict(source_path=self.working_dir, build_path=build_path, install_path=install_path, build_args=self.build_args) ret = {} content = dump_yaml(doc) bezfile = os.path.join(build_path, ".bez.yaml") with open(bezfile, 'w') as f: f.write(content + '\n') if self.write_build_scripts: # write out the script that places the user in a build env, where # they can run bez directly themselves. build_env_script = os.path.join(build_path, "build-env") create_forwarding_script(build_env_script, module=("build_system", "bez"), func_name="_FWD__spawn_build_shell", working_dir=self.working_dir, build_path=build_path, variant_index=variant.index, install=install, install_path=install_path) ret["success"] = True ret["build_env_script"] = build_env_script return ret # run bez in the build environment cmd = ["bez"] if install and "install" not in cmd: cmd.append("install") callback = functools.partial(self._add_build_actions, context=context, package=self.package, variant=variant, build_type=build_type, install=install, build_path=build_path, install_path=install_path) retcode, _, _ = context.execute_shell(command=cmd, block=True, cwd=build_path, actions_callback=callback) ret["success"] = (not retcode) return ret
def save(self, path, verbose=False): """Save the suite to disk. Args: path (str): Path to save the suite to. If a suite is already saved at `path`, then it will be overwritten. Otherwise, if `path` exists, an error is raised. """ path = os.path.realpath(path) if os.path.exists(path): if self.load_path and self.load_path == path: if verbose: print "saving over previous suite..." for context_name in self.context_names: self.context(context_name) # load before dir deleted shutil.rmtree(path) else: raise SuiteError("Cannot save, path exists: %r" % path) contexts_path = os.path.join(path, "contexts") os.makedirs(contexts_path) # write suite data data = self.to_dict() filepath = os.path.join(path, "suite.yaml") with open(filepath, "w") as f: f.write(dump_yaml(data)) # write contexts for context_name in self.context_names: context = self.context(context_name) context._set_parent_suite(path, context_name) filepath = self._context_path(context_name, path) if verbose: print "writing %r..." % filepath context.save(filepath) # create alias wrappers tools_path = os.path.join(path, "bin") os.makedirs(tools_path) if verbose: print "creating alias wrappers in %r..." % tools_path tools = self.get_tools() for tool_alias, d in tools.iteritems(): tool_name = d["tool_name"] context_name = d["context_name"] if verbose: print ("creating %r -> %r (%s context)..." % (tool_alias, tool_name, context_name)) filepath = os.path.join(tools_path, tool_alias) create_forwarding_script(filepath, module="suite", func_name="_FWD__invoke_suite_tool_alias", context_name=context_name, tool_name=tool_name)
def _dump_package_data_yaml(items, buf): for i, (key, value) in enumerate(items): if isinstance(value, SourceCode) \ and key in ("commands", "pre_commands", "post_commands"): value = _commented_old_command_annotations(value) d = {key: value} txt = dump_yaml(d) print >> buf, txt if i < len(items) - 1: print >> buf, ''
def build(self, context, variant, build_path, install_path, install=False, build_type=BuildType.local): # communicate args to bez by placing in a file doc = dict( source_path=self.working_dir, build_path=build_path, install_path=install_path, build_args=self.build_args) ret = {} content = dump_yaml(doc) bezfile = os.path.join(build_path, ".bez.yaml") with open(bezfile, 'w') as f: f.write(content + '\n') if self.write_build_scripts: # write out the script that places the user in a build env, where # they can run bez directly themselves. build_env_script = os.path.join(build_path, "build-env") create_forwarding_script(build_env_script, module=("build_system", "bez"), func_name="_FWD__spawn_build_shell", working_dir=self.working_dir, build_path=build_path, variant_index=variant.index, install=install, install_path=install_path) ret["success"] = True ret["build_env_script"] = build_env_script return ret # run bez in the build environment cmd = ["bez"] if install and "install" not in cmd: cmd.append("install") callback = functools.partial(self._add_build_actions, context=context, package=self.package, variant=variant, build_type=build_type, install=install, build_path=build_path, install_path=install_path) retcode, _, _ = context.execute_shell(command=cmd, block=True, cwd=build_path, actions_callback=callback) ret["success"] = (not retcode) return ret
def create_forwarding_script(filepath, module, func_name, *nargs, **kwargs): """Create a 'forwarding' script. A forwarding script is one that executes some arbitrary Rez function. This is used internally by Rez to dynamically create a script that uses Rez, even though the parent environment may not be configured to do so. """ doc = dict(module=module, func_name=func_name) if nargs: doc["nargs"] = nargs if kwargs: doc["kwargs"] = kwargs body = dump_yaml(doc) create_executable_script(filepath, body, "_rez_fwd")
def create_forwarding_script(filepath, module, func_name, *nargs, **kwargs): """Create a 'forwarding' script. A forwarding script is one that executes some arbitrary Rez function. This is used internally by Rez to dynamically create a script that uses Rez, even though the parent environment may not be configured to do so. """ doc = dict( module=module, func_name=func_name) if nargs: doc["nargs"] = nargs if kwargs: doc["kwargs"] = kwargs body = dump_yaml(doc) create_executable_script(filepath, body, "_rez_fwd")
def create_forwarding_script(filepath, module, func_name, *nargs, **kwargs): """Create a 'forwarding' script. A forwarding script is one that executes some arbitrary Rez function. This is used internally by Rez to dynamically create a script that uses Rez, even though the parent environment may not be configured to do so. """ from rez.utils.platform_ import platform_ if (platform_.name == "windows" and os.path.splitext(filepath)[-1].lower() != ".cmd"): filepath += ".cmd" doc = dict(module=module, func_name=func_name) if nargs: doc["nargs"] = nargs if kwargs: doc["kwargs"] = kwargs body = dump_yaml(doc) create_executable_script(filepath, body, "_rez_fwd")
def save(self, path, verbose=False): """Save the suite to disk. Args: path (str): Path to save the suite to. If a suite is already saved at `path`, then it will be overwritten. Otherwise, if `path` exists, an error is raised. """ path = os.path.realpath(path) if os.path.exists(path): if self.load_path and self.load_path == path: if verbose: print "saving over previous suite..." for context_name in self.context_names: self.context(context_name) # load before dir deleted shutil.rmtree(path) else: raise SuiteError("Cannot save, path exists: %r" % path) contexts_path = os.path.join(path, "contexts") os.makedirs(contexts_path) # write suite data data = self.to_dict() filepath = os.path.join(path, "suite.yaml") with open(filepath, "w") as f: f.write(dump_yaml(data)) # write contexts for context_name in self.context_names: context = self.context(context_name) context._set_parent_suite(path, context_name) filepath = self._context_path(context_name, path) if verbose: print "writing %r..." % filepath context.save(filepath) # create alias wrappers tools_path = os.path.join(path, "bin") os.makedirs(tools_path) if verbose: print "creating alias wrappers in %r..." % tools_path tools = self.get_tools() for tool_alias, d in tools.iteritems(): tool_name = d["tool_name"] context_name = d["context_name"] data = self._context(context_name) prefix_char = data.get("prefix_char") if verbose: print ("creating %r -> %r (%s context)..." % (tool_alias, tool_name, context_name)) filepath = os.path.join(tools_path, tool_alias) create_forwarding_script( filepath, module="suite", func_name="_FWD__invoke_suite_tool_alias", context_name=context_name, tool_name=tool_name, prefix_char=prefix_char, )
def _write_stub(self, data): with open(os.path.join(self.vcs_root, '.stub'), 'w') as f: f.write(dump_yaml(data))
def command(opts, parser, extra_arg_groups=None): from rez.config import config from rez.utils.yaml import dump_yaml from rez.utils.memcached import Client from rez.utils.formatting import columnise, readable_time_duration, \ readable_memory_size import sys memcache_client = Client(servers=config.memcached_uri, debug=config.debug_memcache) if not memcache_client: print >> sys.stderr, "memcaching is not enabled." sys.exit(1) if opts.poll: poll(memcache_client, opts.interval) return if opts.flush: memcache_client.flush(hard=True) print "memcached servers are flushed." return if opts.reset_stats: memcache_client.reset_stats() print "memcached servers are stat reset." return def _fail(): print >> sys.stderr, "memcached servers are not responding." sys.exit(1) stats = memcache_client.get_stats() if opts.stats: if stats: txt = dump_yaml(stats) print txt else: _fail() return # print stats summary if not stats: _fail() rows = [["CACHE SERVER", "UPTIME", "HITS", "MISSES", "HIT RATIO", "MEMORY", "USED"], ["------------", "------", "----", "------", "---------", "------", "----"]] for server_id, stats_dict in stats: server_uri = server_id.split()[0] uptime = int(stats_dict.get("uptime", 0)) hits = int(stats_dict.get("get_hits", 0)) misses = int(stats_dict.get("get_misses", 0)) memory = int(stats_dict.get("limit_maxbytes", 0)) used = int(stats_dict.get("bytes", 0)) hit_ratio = float(hits) / max(hits + misses, 1) hit_percent = int(hit_ratio * 100.0) used_ratio = float(used) / max(memory, 1) used_percent = int(used_ratio * 100.0) row = (server_uri, readable_time_duration(uptime), str(hits), str(misses), "%d%%" % hit_percent, readable_memory_size(memory), "%s (%d%%)" % (readable_memory_size(used), used_percent)) rows.append(row) print '\n'.join(columnise(rows))
def save(self, path, verbose=False): """Save the suite to disk. Args: path (str): Path to save the suite to. If a suite is already saved at `path`, then it will be overwritten. Otherwise, if `path` exists, an error is raised. verbose (bool): Show more messages. """ if verbose and self._is_live: print("saving live suite...") # todo: # 1. instead of wiping it all out, cherry-pick tools to update/remove # by requests. # 2. make a copy of current suite (in timestamp dir) path = os.path.realpath(path) if os.path.exists(path): if self.load_path and self.load_path == path: if verbose: print("saving over previous suite...") for context_name in self.context_names: self.context(context_name) # load before dir deleted forceful_rmtree(path) else: raise SuiteError("Cannot save, path exists: %r" % path) os.makedirs(path) # write suite data data = self.to_dict() filepath = os.path.join(path, "suite.yaml") with open(filepath, "w") as f: f.write(dump_yaml(data)) # write contexts for context_name in self.context_names: context = self.context(context_name) context._set_parent_suite(path, context_name) # noqa self._save_context_rxt(context_name, context, path) # create alias wrappers tools_path = os.path.join(path, "bin") os.makedirs(tools_path) if verbose: print("creating alias wrappers in %r..." % tools_path) tools = self.get_tools() for tool_alias, d in tools.items(): tool_name = d["tool_name"] context_name = d["context_name"] data = self._context(context_name) prefix_char = data.get("prefix_char") if verbose: print("creating %r -> %r (%s context)..." % (tool_alias, tool_name, context_name)) filepath = os.path.join(tools_path, tool_alias) if self._is_live: context = data["context"] requests = [str(r) for r in context.requested_packages()] kwargs = { "module": ("command", "sweet"), # rez plugin "func_name": "_FWD__invoke_suite_tool_alias_in_live", "package_requests": requests, "context_name": context_name, "tool_name": tool_name, "prefix_char": prefix_char, } else: kwargs = { "module": "suite", "func_name": "_FWD__invoke_suite_tool_alias", "context_name": context_name, "tool_name": tool_name, "prefix_char": prefix_char, } create_forwarding_script(filepath, **kwargs)
def command(opts, parser, extra_arg_groups=None): from rez.config import config from rez.utils.yaml import dump_yaml from rez.utils.memcached import Client from rez.utils.formatting import columnise, readable_time_duration, \ readable_memory_size import sys memcache_client = Client(servers=config.memcached_uri, debug=config.debug_memcache) if not memcache_client: print >> sys.stderr, "memcaching is not enabled." sys.exit(1) if opts.poll: poll(memcache_client, opts.interval) return if opts.flush: memcache_client.flush(hard=True) print "memcached servers are flushed." return if opts.reset_stats: memcache_client.reset_stats() print "memcached servers are stat reset." return def _fail(): print >> sys.stderr, "memcached servers are not responding." sys.exit(1) stats = memcache_client.get_stats() if opts.stats: if stats: txt = dump_yaml(stats) print txt else: _fail() return # print stats summary if not stats: _fail() rows = [[ "CACHE SERVER", "UPTIME", "HITS", "MISSES", "HIT RATIO", "MEMORY", "USED" ], [ "------------", "------", "----", "------", "---------", "------", "----" ]] for server_id, stats_dict in stats: server_uri = server_id.split()[0] uptime = int(stats_dict.get("uptime", 0)) hits = int(stats_dict.get("get_hits", 0)) misses = int(stats_dict.get("get_misses", 0)) memory = int(stats_dict.get("limit_maxbytes", 0)) used = int(stats_dict.get("bytes", 0)) hit_ratio = float(hits) / max(hits + misses, 1) hit_percent = int(hit_ratio * 100.0) used_ratio = float(used) / max(memory, 1) used_percent = int(used_ratio * 100.0) row = (server_uri, readable_time_duration(uptime), str(hits), str(misses), "%d%%" % hit_percent, readable_memory_size(memory), "%s (%d%%)" % (readable_memory_size(used), used_percent)) rows.append(row) print '\n'.join(columnise(rows))
def command(opts, parser, extra_arg_groups=None): from rez.config import config from rez.packages_ import iter_package_families, iter_packages from rez.utils.yaml import dump_yaml from rez.utils.memcached import Client from rez.utils.formatting import columnise, readable_time_duration, \ readable_memory_size import sys memcache_client = Client(servers=config.memcached_uri, debug=config.debug_memcache) if not memcache_client: print("memcaching is not enabled.", file=sys.stderr) sys.exit(1) if opts.poll: poll(memcache_client, opts.interval) return if opts.flush: memcache_client.flush(hard=True) print("memcached servers are flushed.") return if opts.warm: seen = set() paths = config.nonlocal_packages_path for family in iter_package_families(paths=paths): if family.name in seen: continue for package in iter_packages(family.name, paths=paths): if opts.verbose: print("warming: %s" % package.qualified_name) # forces package definition load, which puts in memcache _ = package.data # noqa seen.add(family.name) print("memcached servers are warmed.") return if opts.reset_stats: memcache_client.reset_stats() print("memcached servers are stat reset.") return def _fail(): print("memcached servers are not responding.", file=sys.stderr) sys.exit(1) stats = memcache_client.get_stats() if opts.stats: if stats: txt = dump_yaml(stats) print(txt) else: _fail() return # print stats summary if not stats: _fail() rows = [["CACHE SERVER", "UPTIME", "HITS", "MISSES", "HIT RATIO", "MEMORY", "USED"], ["------------", "------", "----", "------", "---------", "------", "----"]] for server_id, stats_dict in stats: server_uri = server_id.split()[0] uptime = int(stats_dict.get("uptime", 0)) hits = int(stats_dict.get("get_hits", 0)) misses = int(stats_dict.get("get_misses", 0)) memory = int(stats_dict.get("limit_maxbytes", 0)) used = int(stats_dict.get("bytes", 0)) hit_ratio = float(hits) / max(hits + misses, 1) hit_percent = int(hit_ratio * 100.0) used_ratio = float(used) / max(memory, 1) used_percent = int(used_ratio * 100.0) row = (server_uri, readable_time_duration(uptime), str(hits), str(misses), "%d%%" % hit_percent, readable_memory_size(memory), "%s (%d%%)" % (readable_memory_size(used), used_percent)) rows.append(row) print('\n'.join(columnise(rows)))