def _install_package(self, pm, desc, bt): if check.is_string(desc): desc = PD.parse(desc) check.check_package_descriptor(desc) if check.is_string(bt): bt = BT.parse_path(bt) check.check_build_target(bt) pm.install_package(desc, bt, ['RUN'])
def __new__(clazz, name, unixpath, pythonpath, requires): check.check_string(name) unixpath = unixpath or [] if check.is_string(unixpath): unixpath = unixpath.split(':') check.check_string_seq(unixpath) pythonpath = pythonpath or [] if check.is_string(pythonpath): pythonpath = pythonpath.split(':') check.check_string_seq(pythonpath) requires = requires or set() check.check_set(requires) return clazz.__bases__[0].__new__(clazz, name, unixpath, pythonpath, requires)
def __new__(clazz, filename, name, version, revision, epoch, system, level, arch, distro, distro_version, requirements, properties, files): check.check_string(filename) check.check_string(name) check.check_string(version) revision = int(revision) check.check_int(revision) epoch = int(epoch) check.check_int(epoch) check.check_string(system) check.check_string(level) arch = build_arch.check_arch(arch, system, distro) check.check_tuple(arch) check.check_string(distro) check.check_string(distro_version) if check.is_string(requirements): requirements = requirement_list.parse(requirements) requirements = requirements or requirement_list() check.check_requirement_list(requirements) properties = properties or {} check.check_dict(properties) check.check_package_files(files) return clazz.__bases__[0].__new__(clazz, 2, filename, name, version, revision, epoch, system, level, arch, distro, distro_version, requirements, properties, files)
def parse_category(clazz, category): if check.is_int(category): if category in clazz.CATEGORIES: return clazz.CATEGORIES[category] elif check.is_string(category): if category.lower() in clazz.CATEGORY_NAMES: return category.lower() raise ValueError('Invalid category: %s' % (str(category)))
def __eq__(self, other): if isinstance(other, self.__class__): return self.value == other.value elif check.is_string(other): return self.name == other elif check.is_int(other): return self.value == other else: raise TypeError('invalid other: %s - %s' % (str(other), type(other)))
def get_property(self, key, default_value=None): kv = self._properties.find_by_last_key(key) if not kv: value = default_value else: value = kv.value if check.is_string(value): value = self.substitute(value) return value
def resolve(clazz, what): if check.is_string(what): return clazz([ package_descriptor.parse(pkg_descs) ]) elif check.is_string_seq(what): return clazz([ package_descriptor.parse(p) for p in what ]) elif check.is_package_descriptor(what): return clazz([ what ]) elif check.is_package_descriptor_seq(what): return what else: raise TypeError('Cannot resolve to package descriptor list: %s - %s' % (str(what), type(what)))
def _determine_args_definition(clazz): defs = clazz.define_args() if check.is_string(defs): try: defs = value_definition.parse_many(defs) except RuntimeError as ex: filename = inspect.getfile(clazz.define_args) line_number = inspect.getsourcelines(clazz.define_args)[1] raise RuntimeError('%s: %s:%s' % (ex.message, filename, line_number)) check.check_dict(defs) return defs
def normalize(clazz, arch): 'Normalize arch into a tuple.' if check.is_string(arch): return tuple(sorted(clazz.split(arch))) elif check.is_string_seq(arch): result = [] for a in arch: result.extend(list(clazz.split(a))) return tuple(sorted(result)) else: raise TypeError('Invalid type for arch: %s - %s' % (str(arch), type(arch)))
def create_package(self, adesc, mutations={}): if check.is_string(adesc): adesc = artifact_descriptor.parse(adesc) check.check_artifact_descriptor(adesc) key = str(adesc) if not key in self._recipes: raise KeyError('recipe not found: %s' % (key)) recipe = self._recipes[key] if mutations: recipe = recipe.clone_with_mutations(mutations) tmp_file = temp_file.make_temp_file() return recipe.create_package(tmp_file, debug=self._debug).filename
def __new__(clazz, mask, value, origin=None): if not check.is_value_base(value): if check.is_bool(value): value = value_bool(origin=origin, value=value) elif check.is_int(value): value = value_int(origin=origin, value=value) elif check.is_string(value): value = value_string(origin=origin, value=value) elif check.is_string_list(value) or check.is_string_seq(value): value = value_string_list(origin=origin, values=value) elif check.is_key_value_list(value): value = value_key_values(origin=origin, values=value) if not check.is_value_base(value): raise TypeError('value should be subclass of value_base: %s - %s' % (str(value), type(value))) if origin: check.check_value_origin(origin) return clazz.__bases__[0].__new__(clazz, mask, value)
def test_is_string_seq(self): self.assertFalse( C.is_string([ 'foo' ]) ) self.assertTrue( C.is_string('foo') )
def __eq__(self, other): if check.is_string(other): return self.value == other return self.value == other.value
def __contains__(self, v): if check.is_string(v): return self.contains_name(v) return super(instruction, self).__contains__(v)
def __contains__(self, v): if check.is_string(v): return self.contains_key(v) return super(key_value_list, self).__contains__(v)
def _publish_one(self, adesc, mutations): if check.is_string(adesc): adesc = artifact_descriptor.parse(adesc) check.check_artifact_descriptor(adesc) filename = self.create_package(adesc, mutations=mutations) self.am.publish(filename, adesc.build_target, False, None)
def _value_to_string(self, value): if check.is_string(value): return value else: return str(value)