about summary refs log tree commit diff
path: root/pkgs/applications/office/libreoffice/generate-libreoffice-srcs.py
diff options
context:
space:
mode:
authorChris Martin <ch.martin@gmail.com>2016-09-20 21:50:44 -0400
committerChris Martin <ch.martin@gmail.com>2016-09-21 01:14:17 -0400
commit356bae0aa9c8f77f2776e9736de2d11969c3854f (patch)
treeabc8920a1594e2222737511f1435264797135888 /pkgs/applications/office/libreoffice/generate-libreoffice-srcs.py
parent1cb54e39f0a8cf0eaccbbf9d5a849a3b7a4e04c8 (diff)
libreoffice: md5 -> sha256
Diffstat (limited to 'pkgs/applications/office/libreoffice/generate-libreoffice-srcs.py')
-rwxr-xr-xpkgs/applications/office/libreoffice/generate-libreoffice-srcs.py54
1 files changed, 45 insertions, 9 deletions
diff --git a/pkgs/applications/office/libreoffice/generate-libreoffice-srcs.py b/pkgs/applications/office/libreoffice/generate-libreoffice-srcs.py
index 9af2ef2fd88a6..a32a692675e1e 100755
--- a/pkgs/applications/office/libreoffice/generate-libreoffice-srcs.py
+++ b/pkgs/applications/office/libreoffice/generate-libreoffice-srcs.py
@@ -8,28 +8,64 @@ of the input file, and writes the result to stdout.
 
 todo - Ideally we would move as much as possible into derivation dependencies.
 """
-import collections, itertools, json, re, sys, os
+import collections, itertools, json, re, subprocess, sys, os
 
 def main():
 
+    packages = list(get_packages())
+
+    for x in packages:
+        print(x, file=sys.stderr)
+
     print('[')
 
-    for x in get_packages():
+    for x in packages:
+
+        md5 = x['md5']
+        tarball = x['tarball']
 
-        print('{')
+        url = construct_url(x)
+        print('url: {}'.format(url), file=sys.stderr)
 
-        print('  name = "{}";'.format(x['tarball']))
-        print('  md5 = "{}";'.format(x['md5']))
-        print('  brief = {};'.format('true' if x['brief'] else 'false'))
+        path = download(url, tarball, md5)
+        print('path: {}'.format(path), file=sys.stderr)
 
-        if 'subdir' in x:
-            print('  subDir = "{}";'.format(x['subdir']))
+        sha256 = get_sha256(path)
+        print('sha256: {}'.format(sha256), file=sys.stderr)
 
-        print('}')
+        print('  {')
+        print('    name = "{}";'.format(tarball))
+        print('    url = "{}";'.format(url))
+        print('    sha256 = "{}";'.format(sha256))
+        print('  }')
 
     print(']')
 
 
+def construct_url(x):
+    if x['brief']:
+        return 'http://dev-www.libreoffice.org/src/{}{}'.format(
+            x.get('subdir', ''), x['tarball'])
+    else:
+        return 'http://dev-www.libreoffice.org/src/{}{}-{}'.format(
+            x.get('subdir', ''), x['md5'], x['tarball'])
+
+
+def download(url, name, md5):
+    cmd = ['nix-prefetch-url', url, md5, '--print-path',
+           '--type', 'md5', '--name', name]
+    proc = subprocess.run(cmd, stdout=subprocess.PIPE, check=True,
+                          universal_newlines=True)
+    return proc.stdout.split('\n')[1].strip()
+
+
+def get_sha256(path):
+    cmd = ['sha256sum', path]
+    proc = subprocess.run(cmd, stdout=subprocess.PIPE, check=True,
+                          universal_newlines=True)
+    return proc.stdout.split(' ')[0].strip()
+
+
 def get_packages():
     """
     All of the package data: What's parsed from download.lst,