Esempio n. 1
0
 def make_pkg_config_pc_content(clazz, name, version):
   replacemetns = {
     '@NAME@': name,
     '@VERSION@': version.upstream_version,
     '@LIBS@': '-l%s' % (name),
     '@LIBS_PRIVATE@': '-lpriv',
   }
   return string_util.replace(clazz._PKG_CONFIG_PC_TEMPLATE, replacemetns)
 def parse(self):
     try:
         # Need to hack newlines before and after because the parse will strip them
         text = string_util.replace(self.text, {'\\n': '@@@NL@@@'})
         tree = tree_text_parser.parse(text, strip_comments=True)
         tree.replace_text({'@@@NL@@@': r'\\n'})
     except Exception as ex:
         self._error('failed to parse: %s' % (ex.message))
     return self._parse_tree(tree)
Esempio n. 3
0
 def save(self, root_dir, variables):
     filename = path.join(root_dir, self.basename)
     variables = copy.deepcopy(variables)
     content = string_util.replace(self.template, variables)
     content = content.replace(path.expanduser('~'), '${HOME}')
     if self._content_changed(filename, content):
         file_util.save(filename, content=content, mode=self.mode)
         return True
     return False
Esempio n. 4
0
 def replace(clazz, filename, replacements, backup = True, word_boundary = False):
   assert isinstance(replacements, dict)
   content = file_util.read(filename, codec = 'utf-8')
   new_content = string_util.replace(content, replacements, word_boundary = word_boundary)
   if content == new_content:
     return False
   if backup:
     file_util.backup(filename)
   file_util.save(filename, content = new_content.encode('utf-8'), mode = file_util.mode(filename))
   return True
Esempio n. 5
0
 def format_message(self, message):
     'Format a build message to be as pretty and compact as possible.'
     format_vars = {
         'staged_files_dir': self.staged_files_dir,
         'stage_dir': self.stage_dir,
     }
     formatted_message = message.format(**format_vars)
     replacemetns = {
         self.working_dir: self._shorten_path(self.working_dir),
     }
     return string_util.replace(formatted_message, replacemetns)
Esempio n. 6
0
 def parse(clazz, origin, text, node):
     if origin:
         check.check_value_origin(origin)
     check.check_node(node)
     parts = string_util.split_by_white_space(text)
     if len(parts) < 1:
         raise ValueError('%s: expected filename instead of: %s' %
                          (origin, text))
     where = parts[0]
     rest = string_util.replace(text, {where: ''})
     properties = clazz.parse_properties(rest)
     return clazz(origin=origin, where=where, properties=properties)
 def make_pc_file_content(clazz, prefix, name, description, version,
                          requires, libs, cflags):
     'Make a testing .pc file.'
     replacements = {
         '@PREFIX@': prefix,
         '@NAME@': name,
         '@DESCRIPTION@': description,
         '@VERSION@': version,
         '@REQUIRES@': requires,
         '@LIBS@': libs,
         '@CFLAGS@': cflags,
     }
     return string_util.replace(clazz.PC_FILE_TEMPLATE, replacements)
Esempio n. 8
0
 def parse_expression(self, expression):
     variables = {
         'system': self.system,
         'arch': self._arch_to_string(self.arch),
         'level': self.level,
         'distro': self.distro or 'None',
     }
     dict_util.quote_strings(variables)
     exp_with_vars = variable.substitute(expression, variables)
     constants = {
         'MACOS': 'macos',
         'LINUX': 'linux',
         'RELEASE': 'release',
         'DEBUG': 'debug',
         'RASPBIAN': 'raspbian',
     }
     dict_util.quote_strings(constants)
     exp_with_consts = string_util.replace(exp_with_vars,
                                           constants,
                                           word_boundary=True)
     return eval(exp_with_consts)
Esempio n. 9
0
    def _fix_checksums(clazz, config, checksums, tmp_dir):
        assert not tmp_dir.endswith(path.sep)
        result = file_checksum_list()
        for checksum in checksums:

            long_form = '%s-%s-%s' % (config.build_target.system,
                                      config.build_target.distro,
                                      config.build_target.distro_version)
            short_form = '%s-%s' % (config.build_target.system,
                                    config.build_target.distro_version)

            replacements = {
                tmp_dir + path.sep: '',
                long_form: '$BUILD_PATH',
                short_form: '$BUILD_PATH',
                '-'.join(sorted(config.build_target.arch)): '$ARCH',
            }
            new_filename = string_util.replace(checksum.filename, replacements)
            i = new_filename.rfind('$BUILD_PATH')
            if i > 0:
                new_filename = new_filename[i:]
            fc = file_checksum(new_filename, checksum.checksum)
            result.append(fc)
        return result
Esempio n. 10
0
    def find_in_list(clazz, filenames, name, version):
        'Find the filenames that match name and version.'

        name_replacements = {
            'lib': '',
        }
        name_prefix = clazz._name_prefix(name)
        #print('cACA: name=%s;  name_prefix=%s' % (name, name_prefix))
        if name_prefix:
            name_replacements[name_prefix] = ''
        name = re.escape(
            string_util.replace(name, name_replacements, word_boundary=False))
        version = re.escape(version)
        version = version.replace('\\.', '.')
        version = version.replace('\\-', '.')

        patterns = [
            r'.*%s.*%s.*' % (name, version),
            r'.*%s.*%s.*' % (name.replace('-', '_'), version),
            r'.*%s.*%s.*' % (name.replace('_', '-'), version),
            r'.*%s.*%s.*' % (name.replace('.', '_'), version),
            r'.*%s.*%s.*' % (name.replace('_', '.'), version),
        ]
        expressions = []
        for pattern in patterns:
            expressions.append(re.compile(pattern))
            expressions.append(re.compile(pattern, re.IGNORECASE))

        result = []
        for filename in filenames:
            for i, expression in enumerate(expressions):
                base = path.basename(filename)
                #print('CHECKING %s to %s => %s' % (expression.pattern, base, expression.match(base)))
                if expression.match(base):
                    result.append(filename)
        return sorted(algorithm.unique(result))
Esempio n. 11
0
 def replace_text(self, replacements):
   'Travese the tree and replace text in each node.'
   new_text = string_util.replace(self.data.text, replacements)
   self.data = self.data.__class__(new_text, self.data.line_number)
   for child in self.children:
     child.replace_text(replacements)
Esempio n. 12
0
 def test_replace_dont_word_boundary(self):
   self.assertEqual( 'foo foond bar barut not foobarfoo', SU.replace('a and b but not aba', { 'a': 'foo', 'b': 'bar' }, word_boundary = False) )
Esempio n. 13
0
 def test_replace_word_boundary(self):
   self.assertEqual( 'foo and bar but not aba', SU.replace('a and b but not aba', { 'a': 'foo', 'b': 'bar' }) )
Esempio n. 14
0
 def test_replace(self):
   self.assertEqual( 'foo bar', SU.replace('a b', { 'a': 'foo', 'b': 'bar' }) )
Esempio n. 15
0
 def sanitize_address(clazz, address):
   'Return path for local tarball.'
   return string_util.replace(address, { ':': '_', '/': '_' })