Exemple #1
0
 def testPathCompile(self):
   result = download.PathCompile(
       self.buildinfo, file_name='file.txt', base='/tmp/base')
   self.assertEqual(result, '/tmp/base/file.txt')
   self.buildinfo._active_conf_path = ['sub', 'dir']
   result = download.PathCompile(
       self.buildinfo, file_name='/file.txt', base='/tmp/base')
   self.assertEqual(result, '/tmp/base/sub/dir/file.txt')
   result = download.PathCompile(
       self.buildinfo, file_name='file.txt', base='/tmp/base')
   self.assertEqual(result, '/tmp/base/sub/dir/file.txt')
   self.buildinfo._active_conf_path = ['sub', 'dir/other', 'another/']
   result = download.PathCompile(
       self.buildinfo, file_name='/file.txt', base='/tmp/')
   self.assertEqual(result, '/tmp/sub/dir/other/another/file.txt')
Exemple #2
0
 def Run(self):
   downloader = download.Download()
   for arg in self._args:
     src = arg[0]
     dst = arg[1]
     full_url = download.Transform(src, self._build_info)
     # support legacy untagged short filenames
     if not (download.IsRemote(full_url) or download.IsLocal(full_url)):
       full_url = download.PathCompile(self._build_info, file_name=full_url)
     try:
       file_util.CreateDirectories(dst)
     except file_util.Error as e:
       raise ActionError('Could not create destination directory %s. %s' %
                         (dst, e))
     try:
       downloader.DownloadFile(full_url, dst, show_progress=True)
     except download.DownloadError as e:
       downloader.PrintDebugInfo()
       raise ActionError('Transfer error while downloading %s: %s' %
                         (full_url, str(e)))
     if len(arg) > 2 and arg[2]:
       logging.info('Verifying SHA256 hash for %s.', dst)
       hash_ok = downloader.VerifyShaHash(dst, arg[2])
       if not hash_ok:
         raise ActionError('SHA256 hash for %s was incorrect.' % dst)
Exemple #3
0
  def _Start(self, conf_path, conf_file):
    """Pull and process a config file.

    Args:
      conf_path: The path to the config below root.
      conf_file: A named config file, normally build.yaml.
    """
    self._build_info.ActiveConfigPath(append=conf_path.rstrip('/'))
    try:
      path = download.PathCompile(self._build_info, file_name=conf_file)
      yaml_config = files.Read(path)
    except (files.Error, buildinfo.Error) as e:
      raise ConfigBuilderError(e)
    timer_start = 'start_{}_{}'.format(conf_path.rstrip('/'), conf_file)
    self._task_list.append({
        'path': copy.deepcopy(self._build_info.ActiveConfigPath()),
        'data': {'SetTimer': [timer_start]}
    })
    controls = yaml_config['controls']
    for control in controls:
      if 'pin' not in control or self._MatchPin(control['pin']):
        self._StoreControls(control, yaml_config.get('templates'))
    timer_stop = 'stop_{}_{}'.format(conf_path.rstrip('/'), conf_file)
    self._task_list.append({
        'path': copy.deepcopy(self._build_info.ActiveConfigPath()),
        'data': {'SetTimer': [timer_stop]}
    })
    self._build_info.ActiveConfigPath(pop=True)
Exemple #4
0
    def _Start(self, conf_path, conf_file):
        """Pull and process a config file.

    Args:
      conf_path: The path to the config below root.
      conf_file: A named config file, normally build.yaml.
    """
        self._build_info.ActiveConfigPath(append=conf_path.rstrip('/'))
        try:
            path = download.PathCompile(self._build_info, file_name=conf_file)
            yaml_config = files.Read(path)
        except (files.Error, buildinfo.BuildInfoError) as e:
            raise ConfigBuilderError(e)
        controls = yaml_config['controls']
        for control in controls:
            if 'pin' not in control or self._MatchPin(control['pin']):
                self._StoreControls(control, yaml_config.get('templates'))
        self._build_info.ActiveConfigPath(pop=True)