def load_tool_from_tmp_config( self, repo, repository_id, ctx, ctx_file, work_dir ):
     tool = None
     message = ''
     tmp_tool_config = hg_util.get_named_tmpfile_from_ctx( ctx, ctx_file, work_dir )
     if tmp_tool_config:
         tool_element, error_message = xml_util.parse_xml( tmp_tool_config )
         if tool_element is None:
             return tool, message
         # Look for external files required by the tool config.
         tmp_code_files = []
         external_paths = Tool.get_externally_referenced_paths( tmp_tool_config )
         for path in external_paths:
             tmp_code_file_name = hg_util.copy_file_from_manifest( repo, ctx, path, work_dir )
             if tmp_code_file_name:
                 tmp_code_files.append( tmp_code_file_name )
         tool, valid, message = self.load_tool_from_config( repository_id, tmp_tool_config )
         for tmp_code_file in tmp_code_files:
             try:
                 os.unlink( tmp_code_file )
             except:
                 pass
         try:
             os.unlink( tmp_tool_config )
         except:
             pass
     return tool, message
Esempio n. 2
0
 def load_tool_from_tmp_config(self, repo, repository_id, ctx, ctx_file,
                               work_dir):
     tool = None
     valid = False
     message = ''
     tmp_tool_config = hg_util.get_named_tmpfile_from_ctx(
         ctx, ctx_file, work_dir)
     if tmp_tool_config:
         tool_element, error_message = xml_util.parse_xml(tmp_tool_config)
         if tool_element is None:
             return tool, message
         # Look for external files required by the tool config.
         tmp_code_files = []
         external_paths = Tool.get_externally_referenced_paths(
             tmp_tool_config)
         changeset_revision = str(ctx)
         for path in external_paths:
             tmp_code_file_name = hg_util.copy_file_from_manifest(
                 repo, changeset_revision, path, work_dir)
             if tmp_code_file_name:
                 tmp_code_files.append(tmp_code_file_name)
         tool, valid, message = self.load_tool_from_config(
             repository_id, tmp_tool_config)
         for tmp_code_file in tmp_code_files:
             try:
                 os.unlink(tmp_code_file)
             except Exception:
                 pass
         try:
             os.unlink(tmp_tool_config)
         except Exception:
             pass
     return tool, valid, message
def __external_files(contents):
    base_path = tempfile.mkdtemp()
    try:
        tool_path = os.path.join(base_path, "tool.xml")
        with open(tool_path, "w") as f:
            f.write(contents)
        return Tool.get_externally_referenced_paths(tool_path)
    finally:
        shutil.rmtree(base_path)
def __external_files(contents):
    base_path = tempfile.mkdtemp()
    try:
        tool_path = os.path.join(base_path, "tool.xml")
        with open(tool_path, "w") as f:
            f.write(contents)
        return Tool.get_externally_referenced_paths(tool_path)
    finally:
        shutil.rmtree(base_path)