tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cipd_from_file.py (2088B)


      1 #!/usr/bin/env python3
      2 # Copyright 2021 The Chromium Authors
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 """Script to generate yaml file based on FILES.cfg."""
      6 
      7 import argparse
      8 import os
      9 
     10 
     11 def _ParseFilesCfg(files_file):
     12  """Return the dictionary of archive file info read from the given file."""
     13  if not os.path.exists(files_file):
     14    raise IOError('Files list does not exist (%s).' % files_file)
     15  exec_globals = {'__builtins__': None}
     16 
     17  exec(open(files_file).read(), exec_globals)
     18  return exec_globals['FILES']
     19 
     20 
     21 def _Process(args):
     22  yaml_content = ('package: ' + args.package + '\ndescription: ' +
     23                  args.description + '\ninstall_mode: ' + args.install_mode +
     24                  '\ndata:\n')
     25  fileobj = _ParseFilesCfg(args.files_file)
     26  for item in fileobj:
     27    if 'buildtype' in item:
     28      if args.buildtype not in item['buildtype']:
     29        continue
     30    if 'arch' in item:
     31      if args.arch not in item['arch']:
     32        continue
     33    if 'type' in item and item['type'] == 'folder':
     34      yaml_content += ' - dir: ' + item['filename'] + '\n'
     35    else:
     36      yaml_content += ' - file: ' + item['filename'] + '\n'
     37 
     38  with open(args.output_yaml_file, 'w') as f:
     39    f.write(yaml_content)
     40 
     41 
     42 def main():
     43  parser = argparse.ArgumentParser()
     44  parser.add_argument('--output_yaml_file', help='File to create.')
     45  parser.add_argument(
     46      '--package',
     47      help='The path where the package will be located inside the CIPD\
     48           repository.')
     49  parser.add_argument(
     50      '--description',
     51      help='Sets the "description" field in CIPD package definition.')
     52  parser.add_argument('--install_mode',
     53                      help='String, should be either "symlink" or "copy".')
     54  parser.add_argument('--files_file',
     55                      help='FILES.cfg describes what files to include.')
     56  parser.add_argument('--buildtype', help='buildtype for FILES.cfg.')
     57  parser.add_argument('--arch', help='arch for FILES.cfg')
     58 
     59  args = parser.parse_args()
     60 
     61  _Process(args)
     62 
     63 
     64 if __name__ == '__main__':
     65  main()