manbytesgnu_site

Source files for manbytesgnu.org
git clone git://holbrook.no/manbytesgnu_site.git
Info | Log | Files | Refs

bundles.py (1021B)


      1 import json
      2 import os
      3 import urllib.request
      4 import urllib.parse
      5 import logging
      6 
      7 logging.basicConfig(level=logging.DEBUG)
      8 logg = logging.getLogger()
      9 
     10 
     11 f = open('package-lock.json', 'r')
     12 j = json.load(f)
     13 f.close()
     14 
     15 script_dir = os.path.dirname(os.path.realpath(__file__))
     16 output_dir = os.path.join(script_dir, '_out')
     17 
     18 for k in j['packages']:
     19     if k == '':
     20         continue
     21     url = j['packages'][k]['resolved']
     22     parts = urllib.parse.urlparse(url)
     23     output_path_package = os.path.join(output_dir, parts.path[1:])
     24     try:
     25         os.stat(output_path_package)
     26         logg.debug('skipping existing {}'.format(output_path_package))
     27         continue
     28     except FileNotFoundError:
     29         pass
     30     output_dir_package = os.path.dirname(output_path_package)
     31     #print(output_path_package)
     32     os.makedirs(output_dir_package, exist_ok=True)
     33 
     34     rq = urllib.request.urlopen(url)
     35     c = rq.read()
     36     f = open(output_path_package, 'wb')
     37     f.write(c)
     38     f.close()
     39     logg.debug('wrote {}'.format(output_path_package))