Beispiel #1
0
 def __init__(self, content, sequence = None, output = None):
     actions = [DSCFileLoader(content, sequence, output), DSCEntryFormatter()]
     for a in actions:
         a(self)
     for name in list(self.keys()):
         if name == 'DSC':
             continue
         else:
             # double check if any computational routines are
             # out of index
             self[name]['meta']['exec'] = [tuple(x.split()) if isinstance(x, str) else x
                                           for x in self[name]['meta']['exec']]
             if ('exec_alias' in self[name]['meta'] and 'rule' not in self[name]['meta'] \
                 and len(self[name]['meta']['exec_alias']) != len(self[name]['meta']['exec'])) or \
                 ('exec_alias' in self[name]['meta'] and 'rule' in self[name]['meta'] \
                  and len(self[name]['meta']['exec_alias']) != len(self[name]['meta']['rule'])):
                 raise FormatError('Alias does not match the length of exec, in block ``{}``!'.\
                                   format(name))
             if 'params' in self[name]:
                 max_exec = max(self[name]['params'].keys())
                 if max_exec > len(self[name]['meta']['exec']):
                     raise FormatError('Index for exec out of range: ``exec[{}]``.'.format(max_exec))
     #
     rlibs = try_get_value(self['DSC'], ('R_libs'))
     if rlibs:
         rlibs_md5 = textMD5(repr(rlibs) + str(datetime.date.today()))
         if not os.path.exists('.sos/.dsc/RLib.{}.info'.format(rlibs_md5)):
             install_r_libs(rlibs)
             os.makedirs('.sos/.dsc', exist_ok = True)
             os.system('echo "{}" > {}'.format(repr(rlibs),
                                               '.sos/.dsc/RLib.{}.info'.format(rlibs_md5)))
Beispiel #2
0
def sos_hash_output(values, db_name):
    if isinstance(values, str):
        values = [values]
    res = []
    for value in values:
        base, ext = value.rsplit('.', 1)
        md5 = '{}.{}'.format(textMD5(base), ext)
        res.append('{}/{}'.format(db_name, md5))
    return res
Beispiel #3
0
def sos_hash_output(values, db_name = '', prefix = None, suffix = None):
     if not isinstance(values, list):
          md5 = textMD5(values)
          if isinstance(prefix, str):
               md5 = '{}:{}'.format(prefix, md5)
          if isinstance(suffix, str):
               md5 = '{}:{}'.format(md5, suffix)
          res = os.path.join(db_name, md5)
          return res
     else:
          res = []
          for value in values:
               md5 = textMD5(value)
               if isinstance(prefix, str):
                    md5 = '{}:{}'.format(prefix, md5)
               if isinstance(suffix, str):
                    md5 = '{}:{}'.format(md5, suffix)
               res.append(os.path.join(db_name, md5))
          return res
Beispiel #4
0
 def RemoveObsoleteOutput(self):
     # Remove file signature when files are deleted
     runtime_dir = os.path.expanduser('~/.sos/.runtime') \
                   if os.path.isabs(os.path.expanduser(self.name)) \
                   else '.sos/.runtime'
     for k, x in self.maps.items():
         x = os.path.join(self.name, x)
         if not os.path.isfile(x):
             try:
                 os.remove('{}/{}.file_info'.\
                           format(runtime_dir, textMD5(os.path.abspath(os.path.expanduser(x)))))
             except:
                 sys.stderr.write('Obsolete file {} has already been purged!\n'.format(x))
Beispiel #5
0
 def __reset_block(self, data, exe, exe_name, exec_path):
     '''Intermediate data to be appended to self.data'''
     data.command = ' '.join([self.__search_exec(exe[0], exec_path)] + list(exe[1:]))
     plugin = Plugin(os.path.splitext(exe[0])[1].lstrip('.'), textMD5(data.command)[:10])
                     # re.sub(r'^([0-9])(.*?)', r'\2', textMD5(data.command)))
     if (data.plugin.name is not None and (not plugin.name) != (not data.plugin.name)):
         raise StepError("A mixture of plugin codes and other executables are not allowed " \
         "in the same block ``{}``.".format(data.name))
     else:
         data.plugin = plugin
     # if data.plugin.name:
     #     executable(data.plugin.name)
     data.plugin.reset()
     data.parameters = []
     # FIXME: currently only one output ext is set
     data.output_ext = []
     data.output_vars = []
     data.exe = ' '.join([x for x in exe if not x.startswith('$')]) if exe_name is None else exe_name