~easypeasy-maintainers/easypeasy-ubufox/main

« back to all changes in this revision

Viewing changes to pfs/db/plugindb.py

  • Committer: Jon Ramvi
  • Date: 2010-04-25 20:49:29 UTC
  • Revision ID: ramvi@ramvi-laptop-20100425204929-xm370mfqkzltvsin
Initial release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#
 
3
# Copyright (C) 2007-2008 Canonical Ltd.
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along
 
16
# with this program; if not, write to the Free Software Foundation, Inc.,
 
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
#
 
19
 
 
20
 
 
21
import threading
 
22
import nppapt
 
23
import sqlite3
 
24
import sys
 
25
 
 
26
if len(sys.argv) < 3:
 
27
        print "CMD <release> <archs>"
 
28
        sys.exit(2)
 
29
 
 
30
releases=sys.argv[1]
 
31
archs=sys.argv[2]
 
32
 
 
33
print "RELEASES", releases
 
34
 
 
35
mimetype_pkgweights = { "application/x-shockwave-flash" : { "flashplugin-nonfree" : 9, "flashplugin-installer" : 9 } }  
 
36
 
 
37
class AptPluginDbUpdater:
 
38
 
 
39
        def __init__ (self, apt_con, configroot):
 
40
                self._apt_con = apt_con
 
41
                self._configroot = configroot
 
42
 
 
43
        def redo_arch_rel_data (self, architecture, rel, entries):
 
44
                self._apt_con.execute('delete from package where architecture=? AND distribution=?', (architecture, rel))
 
45
                for e in entries:
 
46
                        pkgweight = 0
 
47
                        if e.mimetype in mimetype_pkgweights and e.pkgname in mimetype_pkgweights [ e.mimetype ]:
 
48
                                pkgweight = mimetype_pkgweights [ e.mimetype ] [ e.pkgname ]
 
49
 
 
50
                        print "insert into package (pkgname, pkgdesc, pkglongdesc, name, mimetype, architecture, appid, distribution, section, weight, filehint, description) values (?,?,?,?,?,?,\"{"+e.app_id.strip()+"}\",?,?,?,?,?)", \
 
51
                        e.pkgname, e.pkgdesc, e.pkglongdesc, e.name, e.mimetype, architecture, e.distribution, e.section, pkgweight, e.filehint, e.description
 
52
 
 
53
                        try:
 
54
                                self._apt_con.execute("insert into package (pkgname, pkgdesc, pkglongdesc, name, mimetype, architecture, appid, distribution, section, weight, filehint, description) values (?,?,?,?,?,?,\"{"+e.app_id.strip()+"}\",?,?,?,?,?)", \
 
55
                                        (e.pkgname, e.pkgdesc, e.pkglongdesc, e.name, e.mimetype, architecture, e.distribution, e.section, pkgweight, e.filehint, e.description))
 
56
                                print " ... inserted ... "
 
57
                        except Exception, e:
 
58
                                print "ERROR", e.args
 
59
 
 
60
 
 
61
        def geterror (self):
 
62
                return self._error
 
63
 
 
64
        def run(self):
 
65
                i = 0
 
66
                apttmproot = None
 
67
                try:
 
68
                        self._apt_con.execute( \
 
69
                                "CREATE TABLE package " + \
 
70
                                "( id integer PRIMARY KEY," + \
 
71
                                "  pkgname string NOT NULL," + \
 
72
                                "  pkgdesc strong NOT NULL," + \
 
73
                                "  pkglongdesc string NOT NULL," + \
 
74
                                "  name string NOT NULL," + \
 
75
                                "  mimetype string NOT NULL," + \
 
76
                                "  architecture string NULL," + \
 
77
                                "  appid string NOT NULL," + \
 
78
                                "  distribution string NOT NULL," + \
 
79
                                "  section string NOT NULL," + \
 
80
                                "  weight integer NOT NULL," + \
 
81
                                "  filehint integer NOT NULL," + \
 
82
                                "  description integer NOT NULL," + \
 
83
                                "  UNIQUE (pkgname, architecture, appid, mimetype, distribution)" + \
 
84
                                ");")
 
85
 
 
86
                except:
 
87
                        print "table already exists?"
 
88
 
 
89
                try:
 
90
                        apttmproot=nppapt.setup_tmp_cache_tree(self._configroot)
 
91
 
 
92
                        arch_arr = archs.split(" ")
 
93
                        rel_arr = releases.split(" ")
 
94
                        for architecture in arch_arr:
 
95
                                for rel in rel_arr:
 
96
                                        npp_info_entries = nppapt.get_npp_entries_for_arch_and_distribution(apttmproot, architecture, rel)
 
97
                                        self.redo_arch_rel_data(architecture, rel, npp_info_entries)
 
98
                finally:
 
99
                        if not apttmproot is None:
 
100
                                nppapt.tear_down_tmp_cache(apttmproot)
 
101
 
 
102
 
 
103
 
 
104
 
 
105
 
 
106
 
 
107
dbfile="/tmp/apt-plugins.sqlite"
 
108
apt_con = sqlite3.connect(dbfile)
 
109
updater = AptPluginDbUpdater(apt_con, "./")
 
110
updater.run()
 
111
apt_con.commit() 
 
112
apt_con.close()