]> git.donarmstrong.com Git - neurodebian.git/blobdiff - neurodebian/dde.py
Replace a good chunk of code with the new bigmess
[neurodebian.git] / neurodebian / dde.py
index 479e96a8c94d8bb3c21b7c1968beb78840154242..a85459b2b259736c8db8a48a5d25b9217c2a1a91 100755 (executable)
@@ -4,18 +4,21 @@
 
 import pysvn
 import json
-from debian_bundle import deb822
 import numpy as np
-import jinja2
+
+from ConfigParser import SafeConfigParser
+from optparse import OptionParser, OptionGroup, OptionConflictError
 
 # Lets first assure no guarding (but annoying) warnings
 import warnings
 warnings.simplefilter('ignore', FutureWarning)
-warnings.filterwarnings('ignore', 'Module debian_bundle was already imported.*', UserWarning)
+warnings.filterwarnings('ignore',
+                        'Module debian_bundle was already imported.*', UserWarning)
+
+from debian import deb822
+import apt                              # initializes the "_system" ;)
+from apt_pkg import version_compare
 
-import apt
-from ConfigParser import SafeConfigParser
-from optparse import OptionParser, Option, OptionGroup, OptionConflictError
 import sys
 import os
 import copy
@@ -26,6 +29,7 @@ import codecs
 import subprocess
 import time
 import re
+
 # templating
 from jinja2 import Environment, PackageLoader
 
@@ -419,7 +423,7 @@ def dde_get(url, fail=False):
     # enforce delay to be friendly to DDE
     time.sleep(3)
     try:
-        data = json.read(urllib2.urlopen(url+"?t=json").read())['r']
+        data = json.load(urllib2.urlopen(url+"?t=json"))['r']
         print "SUCCESS:", url
         return data
     except urllib2.HTTPError, e:
@@ -436,7 +440,7 @@ def dde_get(url, fail=False):
     except (StopIteration):
         print "NOINFO:", url
         return False
-    except json.ReadException, e:
+    except Exception, e:
         print "UDD-DOWN?:", url, type(e)
         return False
 
@@ -446,7 +450,7 @@ def nitrc_get(spec, fail=False):
     try:
         # change into this from python 2.6 on
         #data = json.loads(urllib2.urlopen(nitrc_url + '?spec=%s' % spec).read())
-        data = json.read(urllib2.urlopen(nitrc_url + '?spec=%s' % spec).read())
+        data = json.load(urllib2.urlopen(nitrc_url + '?spec=%s' % spec))
         print "NITRC-SUCCESS:", spec
     except urllib2.HTTPError, e:
         print "NITRC-NOINFO:", spec, type(e)
@@ -512,7 +516,7 @@ def import_dde(cfg, db):
                 if q.has_key('popcon'):
                     db[p]['main']['debian_popcon'] = q['popcon']
                 # if we have debian, need to get ubuntu
-                q = dde_get(query_url + "/packages/prio-ubuntu-natty/%s" % p)
+                q = dde_get(query_url + "/packages/prio-ubuntu-precise/%s" % p)
                 if q and q.has_key('popcon'):
                     db[p]['main']['ubuntu_popcon'] = q['popcon']
             else:
@@ -534,8 +538,8 @@ def import_dde(cfg, db):
                 info[distkey]['architecture'] = [info[distkey]['architecture']]
             # accumulate data for multiple over archs
             else:
-                comp = apt.VersionCompare(cp['version'],
-                                          info[distkey]['version'])
+                comp = version_compare(cp['version'],
+                                                   info[distkey]['version'])
                 # found another arch for the same version
                 if comp == 0:
                     info[distkey]['architecture'].append(cp['architecture'])
@@ -701,11 +705,14 @@ def generate_pkgpage(pkg, cfg, db, template, addenum_dir, extracts_dir):
         ex_dir = os.path.join(extracts_dir, pkgdb['main']['sv'].split()[0])
         if not os.path.exists(ex_dir):
             ex_dir = None
+    long_description = 'Description missing'
+    if 'long_description' in pkgdb['main']:
+        long_description=convert_longdescr(
+                    assure_unicode(pkgdb['main']['long_description']))
     page = template.render(
             pkg=pkg,
             title=title,
-            long_description=convert_longdescr(
-                assure_unicode(pkgdb['main']['long_description'])),
+            long_description=long_description,
             cfg=cfg,
             db=pkgdb,
             fulldb=db,
@@ -771,6 +778,25 @@ def write_sourceslist(jinja_env, cfg, outdir):
     sl.close()
 
 
+def write_mirmonlists(cfg, outdir):
+    """Write list of mirrors in the format suitable for mirmon
+
+    It will reuse the same 'lists' directory
+    """
+    print "I: Composing mirmon lists"
+    outdir = os.path.join(outdir, 'lists')
+    create_dir(outdir)
+
+    for sec, sep in (('mirrors', ' '),
+                         ('mirror names', ' - ')):
+        entries = ['%s%s%s' % (mirror, sep, cfg.get(sec, mirror))
+                   for mirror in cfg.options('mirrors')]
+        f = open(os.path.join(outdir, 'mirmon-%s.txt' % sec.replace(' ', '-')),
+                 'w')
+        f.write('\n'.join(entries + ['']))
+        f.close()
+
+
 def sort_by_tasks(db):
     tasks = {}
     for pkg in db.keys():
@@ -1027,5 +1053,7 @@ def main():
 
     write_sourceslist(jinja_env, cfg, opts.outdir)
 
+    write_mirmonlists(cfg, opts.outdir)
+
 if __name__ == "__main__":
     main()