contrib/packaging/hgpackaging/downloads.py
changeset 41914 1e8fb6522fee
parent 41913 c2237fe1359e
child 41926 4371f543efda
equal deleted inserted replaced
41913:c2237fe1359e 41914:1e8fb6522fee
     9 
     9 
    10 import gzip
    10 import gzip
    11 import hashlib
    11 import hashlib
    12 import pathlib
    12 import pathlib
    13 import urllib.request
    13 import urllib.request
       
    14 
       
    15 
       
    16 DOWNLOADS = {
       
    17     'gettext': {
       
    18         'url': 'https://versaweb.dl.sourceforge.net/project/gnuwin32/gettext/0.14.4/gettext-0.14.4-bin.zip',
       
    19         'size': 1606131,
       
    20         'sha256': '60b9ef26bc5cceef036f0424e542106cf158352b2677f43a01affd6d82a1d641',
       
    21         'version': '0.14.4',
       
    22     },
       
    23     'gettext-dep': {
       
    24         'url': 'https://versaweb.dl.sourceforge.net/project/gnuwin32/gettext/0.14.4/gettext-0.14.4-dep.zip',
       
    25         'size': 715086,
       
    26         'sha256': '411f94974492fd2ecf52590cb05b1023530aec67e64154a88b1e4ebcd9c28588',
       
    27     },
       
    28     'py2exe': {
       
    29         'url': 'https://versaweb.dl.sourceforge.net/project/py2exe/py2exe/0.6.9/py2exe-0.6.9.zip',
       
    30         'size': 149687,
       
    31         'sha256': '6bd383312e7d33eef2e43a5f236f9445e4f3e0f6b16333c6f183ed445c44ddbd',
       
    32         'version': '0.6.9',
       
    33     },
       
    34     'virtualenv': {
       
    35         'url': 'https://files.pythonhosted.org/packages/37/db/89d6b043b22052109da35416abc3c397655e4bd3cff031446ba02b9654fa/virtualenv-16.4.3.tar.gz',
       
    36         'size': 3713208,
       
    37         'sha256': '984d7e607b0a5d1329425dd8845bd971b957424b5ba664729fab51ab8c11bc39',
       
    38         'version': '16.4.3',
       
    39     },
       
    40 }
    14 
    41 
    15 
    42 
    16 def hash_path(p: pathlib.Path):
    43 def hash_path(p: pathlib.Path):
    17     h = hashlib.sha256()
    44     h = hashlib.sha256()
    18 
    45 
   103 
   130 
   104     tmp.rename(path)
   131     tmp.rename(path)
   105     print('successfully downloaded %s' % url)
   132     print('successfully downloaded %s' % url)
   106 
   133 
   107 
   134 
   108 def download_entry(entry: dict, dest_path: pathlib.Path, local_name=None) -> pathlib.Path:
   135 def download_entry(name: dict, dest_path: pathlib.Path, local_name=None) -> pathlib.Path:
       
   136     entry = DOWNLOADS[name]
       
   137 
   109     url = entry['url']
   138     url = entry['url']
   110 
   139 
   111     local_name = local_name or url[url.rindex('/') + 1:]
   140     local_name = local_name or url[url.rindex('/') + 1:]
   112 
   141 
   113     local_path = dest_path / local_name
   142     local_path = dest_path / local_name
   114     download_to_path(url, local_path, entry['size'], entry['sha256'])
   143     download_to_path(url, local_path, entry['size'], entry['sha256'])
   115 
   144 
   116     return local_path
   145     return local_path, entry