def trash(self, what): check.check_string(what) if not self._valid_type(what): raise RuntimeError('Invalid file type: %s' % (what)) if file_util.device_id(what) != self._location_device_id: raise RuntimeError('%s is not in the save filesystem as %s' % (what, self._location)) self.trash_process.trash(what)
def get_class(clazz, value_class_name): check.check_string(value_class_name) value_class = value_registry.get(value_class_name) if not value_class: raise TypeError('unknown value_class_name \"%s\"' % (value_class_name)) return value_class
def __new__(clazz, name, description, values): check.check_string(name) check.check_step_description(description) if not check.is_recipe_value_list(values): values = recipe_value_list(values) check.check_recipe_value_list(values) return clazz.__bases__[0].__new__(clazz, name, description, values)
def __new__(clazz, name, flags, requires): flags = flags or {} requires = requires or set() check.check_string(name) check.check_dict(flags, key_type = check.STRING_TYPES, value_type = string_list) check.check_set(requires, entry_type = check.STRING_TYPES) return clazz.__bases__[0].__new__(clazz, name, flags, requires)
def execute(self, script, env, values, inputs): shell_env = values.get('shell_env') cmd = values.get('cmd') check.check_string(cmd) self.log_d('step_shell.execute() cmd=%s; shell_env=%s' % (cmd, shell_env)) return self.call_shell(cmd, script, env, shell_env=shell_env)
def from_dict(clazz, d): check.check_dict(d) result = clazz() for key, value in sorted(d.items()): check.check_string(key) result.append(key_value(key, value)) return result
def create_with_class_name(clazz, origin, text, node, value_class_name): check.check_value_origin(origin) check.check_string(text) check.check_node(node) check.check_string(value_class_name) value_class = clazz.get_class(value_class_name) return value_class.parse(origin, text, node)
def parse(clazz, text, options = 0, delimiter = '=', empty_value = None, log_tag = None): check.check_string(text) result = clazz() for kv in key_value_parser.parse(text, options = options, delimiter = delimiter, empty_value = empty_value, log_tag = log_tag): result.append(kv) return result
def make_value(clazz, origin, text, node, value_class_name): if origin: check.check_value_origin(origin) check.check_node(node) check.check_string(value_class_name) return value_factory.create_with_class_name(origin, text, node, value_class_name)
def __new__(clazz, filename): filename = path.abspath(filename) check.check_string(filename) file_check.check_file(filename) content = file_util.read(filename, codec = 'utf-8') root_dir = path.normpath(path.join(path.dirname(filename), '..')) data = config_data.parse(content, filename = filename) return clazz.__bases__[0].__new__(clazz, root_dir, filename, data)
def __new__(clazz, config_env, filename): if filename is not None: check.check_string(filename) if not path.isfile(filename): raise IOError('File not found: %s' % (filename)) filename = path.abspath(filename) config = config_env.config_for_filename(filename) return clazz.__bases__[0].__new__(clazz, filename, config)
def __init__(self, root_dir): check.check_string(root_dir) build_blurb.add_blurb(self, label='rebuild') self._root_dir = root_dir self._build_target = build_target self._ignored = set() self._ignore_all = False self._sources = {}
def __new__(clazz, filename, sources, headers, ldflags): check.check_string(filename) check.check_fake_package_source_seq(sources) check.check_fake_package_source_seq(headers) ldflags = ldflags or [] check.check_string_seq(ldflags) return clazz.__bases__[0].__new__(clazz, filename, sources, headers, ldflags)
def _caca_parse_mask_and_value(clazz, origin, text, node, class_name): check.check_value_origin(origin) check.check_string(text) check.check_node(node) check.check_string(class_name) mask, value = recipe_parser_util.split_mask_and_value(text) value = recipe_parser_util.make_value(origin, value, node, class_name) return masked_value(mask, value, origin)
def check_file(clazz, filename): check.check_string(filename) if not path.exists(filename): raise IOError('File not found: %s' % (filename)) if path.isfile(filename): return if path.islink(filename): return raise IOError('Not a file: %s' % (filename))
def __new__(clazz, name, version, revision, epoch, requirements, properties, files): check.check_string(name) check.check_string(version) check.check_int(revision) check.check_int(epoch) check.check_requirement_list(requirements) check.check_dict(properties) check.check_package_files(files) return clazz.__bases__[0].__new__(clazz, 2, name, version, revision, epoch, requirements, properties, files)
def add_recipes(self, recipes, filename=None): filename = filename or '<unknown>' check.check_string(filename) check.check_string(recipes) for recipe in fake_package_recipe_parser(filename, recipes).parse(): key = str(recipe.metadata) if key in self._recipes: raise RuntimeError('Already in recipes: %s' % (key)) self._recipes[key] = recipe
def __new__(clazz, success, message = None, failed_step = None, outputs = None): check.check_bool(success) if message: check.check_string(message) if outputs: outputs = copy.copy(outputs) else: outputs = {} check.check_dict(outputs) return clazz.__bases__[0].__new__(clazz, success, message, failed_step, outputs)
def _parse_many_recipes(clazz, recipe, metadata_mutations): check.check_string(recipe) recipes = fake_package_recipe_parser('<unknown>', recipe).parse() result = [] if metadata_mutations: for r in recipes: result.append(r.clone_with_mutations(metadata_mutations)) else: result = recipes return result
def add_table(self, name, files): 'Does not commit' check.check_string(name) check.check_file_checksum_list(files) table_name = self.table_name(name) assert not self._db.has_table(table_name) schema = self.SCHEMA_FILES.format(table_name = table_name) self._db.execute(schema) for f in files: self._insert_file(table_name, f)
def parse(clazz, text, default_system_mask=None): if check.is_string_seq(text): text = ' '.join(text) check.check_string(text) reqs = clazz([ req for req in requirement_parser.parse( text, default_system_mask=default_system_mask) ]) reqs.remove_dups() return reqs
def search(clazz, root_dir, text, relative = True, min_depth = None, max_depth = None): check.check_string(root_dir) #assert string_util.is_string(text) files = file_find.find(root_dir, relative = relative, min_depth = min_depth, max_depth = max_depth) items = [] for f in files: fpath = path.join(root_dir, f) next_items = clazz.search_file(fpath, text) items += next_items if relative: return [ item.become_relative(root_dir) for item in items ] return items
def dependencies(self, target): check.check_string(target) dependency_map = self._dependency_map() if not target in dependency_map: raise KeyError('target not found: \"%s\"' % (target)) resolved_names = dependency_resolver.resolve_deps( dependency_map, target) resolved_map = dict_util.filter_with_keys(dependency_map, resolved_names) build_order = dependency_resolver.build_order_flat(resolved_map) build_order.remove(target) return build_order
def parse_key_value(clazz, origin, text): check.check_value_origin(origin) check.check_string(text) key, delimiter, value = text.partition(':') key = key.strip() if not key: raise clazz.raise_error( origin, '%s: invalid step value key: \"%s\"' % (origin, text)) if not delimiter: return clazz.parsed_value(None, key, None) value_text = value.strip() or None return clazz.parsed_value(None, key, value_text)
def __new__(clazz, name, version, properties=None, requirements=None): check.check_string(name) if not clazz.name_is_valid(name): raise RuntimeError('Invalid name: \"%s\"' % (name)) version = build_version.validate_version(version) requirements = requirement_list(requirements) check.check_requirement_list(requirements) requirements = clazz.parse_requirements(requirements) properties = properties or {} check.check_dict(properties) return clazz.__bases__[0].__new__(clazz, name, version, requirements, properties)
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 __init__(self, text, delimiter = '\n'): self._delimiter = delimiter if isinstance(text, text_line_parser): self._lines = text._lines[:] self._ends_with_delimiter = False elif check.is_line_token_seq(text): self._assign_line_token_seq(text) elif check.is_seq(text, tuple): tokens = [ line_token(*line) for line in text ] self._assign_line_token_seq(tokens) else: check.check_string(text) self._lines = self._parse(text, self._delimiter) self._ends_with_delimiter = text and text[-1] == self._delimiter
def _search_line_with_find(clazz, line, patterns, filename, line_number, ignore_case): check.check_list(patterns) assert len(patterns) > 0 result = [] original_line = line if ignore_case: line = line.lower() for pattern, original_pattern in patterns: check.check_string(pattern) check.check_string(original_pattern) index = line.find(pattern) if index >= 0: span = clazz.span(index, index + len(pattern)) result.append(clazz.search_item(filename, line_number, original_pattern, original_line, span)) return result
def make_key_value(clazz, origin, text, node, value_class_name): check.check_value_origin(origin) check.check_string(text) check.check_node(node) check.check_string(value_class_name) text = comments.strip_line(text) key, delimiter, value = text.partition(':') key = key.strip() if not key: raise ValueError('%s: invalid step value key: \"%s\"' % (origin, text)) if not delimiter: return key_value(key, None) value_text = value.strip() or None if not value_text: return key_value(key, None) value = value_factory.create_with_class_name(origin, value_text, node, value_class_name) return key_value(key, value)
def __new__(clazz, filename, entries, variables, properties): check.check_string(filename) check.check_caca_pkg_config_entry_seq(entries) check.check_key_value_list(variables) check.check_key_value_list(properties) resolved_variables = variables[:] resolved_variables.substitute_variables(variables.to_dict()) resolved_properties = properties[:] resolved_properties.substitute_variables(resolved_variables.to_dict()) raw_reqs = resolved_properties.find_by_key(clazz.PROPERTY_REQUIRES) if raw_reqs: reqs = clazz._parse_requirements(raw_reqs.value) resolved_properties.replace( clazz.PROPERTY_REQUIRES, key_value(clazz.PROPERTY_REQUIRES, reqs)) else: resolved_properties.append(key_value(clazz.PROPERTY_REQUIRES, [])) return clazz.__bases__[0].__new__(clazz, filename, entries, variables, properties, resolved_variables, resolved_properties)
def __new__(clazz, files, env_files, files_checksum=None, env_files_checksum=None): files = files or file_checksum_list() check.check_file_checksum_list(files) env_files = env_files or file_checksum_list() check.check_file_checksum_list(env_files) if files_checksum: check.check_string(files_checksum) files_checksum = files_checksum or files.checksum() if env_files_checksum: check.check_string(env_files_checksum) env_files_checksum = env_files_checksum or env_files.checksum() return clazz.__bases__[0].__new__(clazz, files, env_files, files_checksum, env_files_checksum)
def __new__(clazz, system, distro, distro_version, arch, level): check.check_string(system) if distro is not None: check.check_string(distro) check.check_string(distro_version) arch = build_arch.check_arch(arch, system, distro) check.check_string(level) system = build_system.parse_system(system) arch = build_arch.determine_arch(arch, system, distro) level = build_level.parse_level(level) build_path = clazz._make_build_path(system, distro, distro_version, arch, level) return clazz.__bases__[0].__new__(clazz, system, distro, distro_version, arch, level, build_path)
def __new__(clazz, filename, fixture, function): if filename is not None: check.check_string(filename) if fixture is not None: check.check_string(fixture) if function is not None: check.check_string(function) return clazz.__bases__[0].__new__(clazz, filename, fixture, function)
def test_string(self): C.check_string('x') with self.assertRaises(TypeError) as context: C.check_string(6) with self.assertRaises(TypeError) as context: C.check_string([ 'a '])
def __new__(clazz, name, class_name, default, line_number): check.check_string(name) check.check_string(class_name) if default != None: check.check_string(default) check.check_int(line_number) return clazz.__bases__[0].__new__(clazz, name, class_name, default, line_number)
def test_string_seq(self): C.check_string_seq(['x']) with self.assertRaises(TypeError) as context: C.check_string_seq(6) C.check_string(6)
def check_dir(clazz, dirname): check.check_string(dirname) if not path.exists(dirname): raise IOError('File not found: %s' % (dirname)) if not path.isdir(dirname): raise IOError('Not a directory: %s' % (dirname))
def save_file(self, filename): check.check_string(filename) with open(filename, 'w') as f: f.write(str(self))
def ensure_table(self, table_name, table_schema): check.check_string(table_name) check.check_string(table_schema) if self.has_table(table_name): return self._cursor.execute(table_schema)
def parse_key(clazz, origin, text): 'Parse only the key' check.check_string(text) key, _, _ = comments.strip_line(text).partition(':') return key.strip()
def read_file(clazz, filename): check.check_string(filename) with open(filename, 'r') as f: return clazz.read_string(f.read())
def replace(self, key, new_kv): check.check_string(key) check.check_key_value(new_kv) for i, next_kv in enumerate(self._values): if next_kv.key == key: self._values[i] = new_kv
def __new__(clazz, version, author_name, author_email, address, tag, timestamp): check.check_string(version) check.check_string(author_name) check.check_string(author_email) check.check_string(address) check.check_string(tag) check.check_string(timestamp) return clazz.__bases__[0].__new__(clazz, version, author_name, author_email, address, tag, timestamp)
def __new__(clazz, directory, patterns): check.check_string(directory) if patterns: check.check_string_seq(patterns) return clazz.__bases__[0].__new__(clazz, directory, patterns)
def __new__(clazz, key, values): check.check_string(key) if not isinstance(values, masked_value_list): values = masked_value_list(values) check.check_masked_value_list(values) return clazz.__bases__[0].__new__(clazz, key, values)
def __init__(self, origin = None, value = None): super(value_string, self).__init__(origin) if value is not None: check.check_string(value) self.value = value
def has_table(self, table_name): check.check_string(table_name) sql = """select count(*) from sqlite_master where type='table' and name='{table_name}'""".format(table_name = table_name) self._cursor.execute(sql) return self._cursor.fetchone()[0] == 1
def parse_description(self, text): check.check_string(text) step_class = step_registry.get(text) if not step_class: raise RuntimeError('no such step class: %s' % (text)) return step_description(step_class)
def set(self, x, y, s): check.check_string(s) self._table.set(x, y, s)
def parse_system(clazz, s): check.check_string(s) systems = clazz.mask_split(clazz.resolve_mask(s)) if len(systems) != 1: raise ValueError('Invalid system: %s' % (str(s))) return systems[0]
def __new__(clazz, text, line_number): check.check_string(text) check.check_int(line_number) return clazz.__bases__[0].__new__(clazz, text, line_number)
def change(self, version = None, author_name = None, author_email = None, address = None, tag = None, timestamp = None): if version is not None: check.check_string(version) else: version = self.version if author_name is not None: check.check_string(author_name) else: author_name = self.author_name if author_email is not None: check.check_string(author_email) else: author_email = self.author_email if address is not None: check.check_string(address) else: address = self.address if tag is not None: check.check_string(tag) else: tag = self.tag if timestamp is not None: check.check_string(timestamp) else: timestamp = self.timestamp return self.__class__(version, author_name, author_email, address, tag, timestamp)
def __new__(clazz, filename, checksum): check.check_string(filename) check.check_string(checksum) return clazz.__bases__[0].__new__(clazz, filename, checksum)
def __init__(self, origin=None, filename='', properties=None): 'Class to manage a recipe file.' super(value_file, self).__init__(origin, properties=properties) check.check_string(filename) self._filename = filename
def __new__(clazz, filename, line_number, text): check.check_string(filename) check.check_int(line_number) check.check_string(text) return clazz.__bases__[0].__new__(clazz, filename, line_number, text)
def __init__(self, text, column_widths): check.check_string(text) check.check_tuple(column_widths) self.table = self._parse(text, column_widths)