~inspirated/arsenal/send-attachments-lpltk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/python

import sys, glob, re
from template import Template
from template.util import TemplateException, Literal
import simplejson as json

if len(sys.argv) < 2:
    sys.stderr.write("Usage: " + sys.argv[0] + " <tag> <source-package>\n")
    exit(1)

TEMPLATE_MAIN    = "templates/main.tt2"
TEMPLATE_CONTENT = "templates/table.tt2"
# TODO:  Can the pkg-page tt2 fit into the table.tt2 template?

tag    = "historical-packages"
tt2    = Template()

# TODO:
# * (DONE) Code to load up the json files into the debs data structure
# * Stop loading stylesheets from launchpad; set up a script to pull down
#   newer versions of the stylesheet to snapshot
# * Come up with file hierarchy for json files
# * Create 10 sample json files to work with
# * What other data members should be in the json file format?
# * Should the data structure be renamed?
# * Add mechanism for handling changes in the debian/ dir version
# * Add mechanism for tracking pre-requisites
# * Can this be generalized further to be less xorg-specific?
# * Create an external json file with the rels data structure
#
# * Set up four git trees:
#   - xf86-video-intel
#   - xf86-video-ati
#   - xf86-video-nv
#   - xf86-input-evdev
# * For each of the above create a bash constants file
# * Test git-commit-log with all four of the above packages
# * Review git-pkg
# * Test running git-pkg on all commit id's from running git-commit-log
#
# * Plan if this can be run as daemon or needs run manually
# * Plan out web interface
            
rels = { 'hardy':1,
         'intrepid':1,
         'jaunty':1,
         'karmic':1 }
# TODO:  Use rels to fill in columns
columns = [
    { 'title': 'Name',     'field': 'name',          'format': 'string' },
    { 'title': 'Version',  'field': 'version',       'format': 'string' },
    { 'title': 'hardy',    'field': 'hardy-debs',    'format': 'string' },
    { 'title': 'intrepid', 'field': 'intrepid-debs', 'format': 'string' },
    { 'title': 'jaunty',   'field': 'jaunty-debs',   'format': 'string' },
    { 'title': 'karmic',   'field': 'karmic-debs',   'format': 'string' },
    ]
rows = []
hide_filters = []
releases = []

# TODO:  Isn't there a better way to handle regex's?
regex_ubuntu_pre = re.compile('ubuntu.*~.*', re.IGNORECASE)
regex_ubuntu     = re.compile('ubuntu', re.IGNORECASE)
regex_debian     = re.compile('-', re.IGNORECASE)
regex_xorg_pre   = re.compile('\.9', re.IGNORECASE)


# Load directory-full of json files
for file in glob.glob("/home/bryce/src/Arsenal/arsenal/web/data/*.json"):
    fp = open(file)
    entries = json.load(fp)
    for d in entries:
        # TODO:  Combine rows with same d['version'] and same d['version']
        #        Possibly, do this by instead of putting d into a plain list,
        #         put it into a deeper data structure keyed by release name,
        releases.append(d)

# TODO:  Document the releases.json file format

# Algorthim:
#  1.  Take each deb from json files
#  2.  Organize into a data structure by release name
#  3.  In TT2, generate the page

for r in releases:
    # TODO:  It'd be nice to have a lookup table or something cleaner than regex's...
    if not r.has_key('release'):
        r['version'] = r['commit_short']
        # TODO:  Set up version string according to debian rules
    elif r['release'] == 'master':
        r['version'] = r['commit_short']
        r['name'] = 'Xorg-git (master)'
    elif regex_ubuntu_pre.search(r['release']):
        r['version'] = r['release']
    elif regex_ubuntu.search(r['release']):
        r['version'] = r['release']
    elif regex_debian.search(r['release']):
        r['version'] = r['release']
        r['name'] = 'Debian'
    elif regex_xorg_pre.search(r['release']):
        r['version'] = r['release']
        r['name'] = 'Xorg (Pre-Release)'
    else:
        # TODO:  This can't be the right settings for an unknown default...??
        r['version'] = r['release']
        r['name'] = 'Xorg (Release)'

        # Prepend a label for Ubuntu/Debian packages
        # TODO:  Make sure this is getting filled in - or do it via json files
        if rels.has_key(r['release']):
            rows.append(rels[r['release']])

    # Stick in html in hardy-debs, etc.
    if r.has_key('debs'):
        for d in r['debs']:
            if d.has_key('deb'):
                value = '<b><a href="%s">%s</a></b>' % (d['deb'], d['arch'])
            if d.has_key('dbg'):
                value = value + '&nbsp;[<a href="%s">dbg</a>]' % (d['dbg'])
            field = "%s-debs" % d['dist']
            if not r.has_key(field):
                r[field] = value
            else:
                r[field] = r[field] + "<br>" + value

    rows.append(r)

# TODO:  Extract debian sorting algorithms from versions_current script

try:
    content = tt2.process(TEMPLATE_CONTENT, {
            'table_name': 'Historical Package Page',
            'columns': columns,
            'sort_column': 'version',
            'data': rows,
            'hiderows': hide_filters
            } )
    # TODO:  The stylesheet needs cleanup - stuff particular to the bisect page
    #        needs redone to be more general purpose.  Maybe style overrides in
    #        general need to be handled in a better way
    print tt2.process(TEMPLATE_MAIN, {
            'title': 'Historical Package Page',
            'content': content
            } )
except TemplateException, e:
    print >>sys.stderr, "ERROR: %s" % e