~ubuntu-branches/ubuntu/utopic/ubufox/utopic-updates

« back to all changes in this revision

Viewing changes to pfs/db/plugindb.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2015-01-09 19:41:13 UTC
  • mfrom: (1.3.6)
  • Revision ID: package-import@ubuntu.com-20150109194113-ejz9f5v0slwiz5vq
Tags: 3.0-0ubuntu0.14.10.1
* New upstream release
  - Delete the plugin installer wizard implementation and associated code.
    Upstream have disabled PFS and removed their plugin installer wizard now
  - Drop the search engine defaults - these have moved to Firefox
    (LP: #1398174)

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
 
import json
26
 
 
27
 
if len(sys.argv) < 3:
28
 
        print "CMD <release> <archs>"
29
 
        sys.exit(2)
30
 
 
31
 
releases=sys.argv[1]
32
 
archs=sys.argv[2]
33
 
 
34
 
print "RELEASES", releases
35
 
 
36
 
mimetype_pkgweights = { "application/x-shockwave-flash" : { "flashplugin-nonfree" : 9, "flashplugin-installer" : 9 } }  
37
 
 
38
 
class AptPluginDbUpdater:
39
 
 
40
 
        def __init__ (self, apt_con, configroot):
41
 
                self._apt_con = apt_con
42
 
                self._configroot = configroot
43
 
 
44
 
        def redo_arch_rel_data (self, architecture, rel, entries):
45
 
                self._apt_con.execute('delete from package where architecture=? AND distribution=?', (architecture, rel))
46
 
                for e in entries:
47
 
                        pkgweight = 0
48
 
                        if e.mimetype in mimetype_pkgweights and e.pkgname in mimetype_pkgweights [ e.mimetype ]:
49
 
                                pkgweight = mimetype_pkgweights [ e.mimetype ] [ e.pkgname ]
50
 
 
51
 
                        print "insert into package (pkgname, pkgdesc, pkglongdesc, name, mimetype, architecture, appid, distribution, section, weight, filehint, description, manualInstallURL) values (?,?,?,?,?,?,\"{"+e.app_id.strip()+"}\",?,?,?,?,?,\"\")", \
52
 
                        e.pkgname, e.pkgdesc, e.pkglongdesc, e.name, e.mimetype, architecture, e.distribution, e.section, pkgweight, e.filehint, e.description
53
 
 
54
 
                        try:
55
 
                                self._apt_con.execute("insert into package (pkgname, pkgdesc, pkglongdesc, name, mimetype, architecture, appid, distribution, section, weight, filehint, description, manualInstallURL) values (?,?,?,?,?,?,\"{"+e.app_id.strip()+"}\",?,?,?,?,?,\"\")", \
56
 
                                        (e.pkgname, e.pkgdesc, e.pkglongdesc, e.name, e.mimetype, architecture, e.distribution, e.section, pkgweight, e.filehint, e.description))
57
 
                                print " ... inserted ... "
58
 
                        except Exception, e:
59
 
                                print "ERROR", e.args
60
 
 
61
 
        def add_extra_data (self, arch, dist):
62
 
                fd = open('extra.json', 'r')
63
 
                extras = json.load(fd)
64
 
                fd.close()
65
 
 
66
 
                for mimetype in extras['mimetypes']:
67
 
                        entry = extras['mimetypes'][mimetype]
68
 
                        for appid in extras[entry]['appids']:
69
 
                                print "insert into package (pkgname, pkgdesc, pkglongdesc, name, mimetype, architecture, appid, distribution, section, weight, filehint, description, manualInstallURL) values (\"\",\"\",\"\",?,?,?,\"{"+appid+"}\",?,\"\",\"\",\"\",?,?)", extras[entry]['name'], mimetype, arch, dist, extras[entry]['description'], extras[entry]['manualInstallURL']
70
 
 
71
 
                                try:
72
 
                                        self._apt_con.execute("insert into package (pkgname, pkgdesc, pkglongdesc, name, mimetype, architecture, appid, distribution, section, weight, filehint, description, manualInstallURL) values (\"\",\"\",\"\",?,?,?,\"{"+appid+"}\",?,\"\",-1,\"\",?,?)", (extras[entry]['name'], mimetype, arch, dist, extras[entry]['description'], extras[entry]['manualInstallURL']))
73
 
                                        print " ... inserted ... "
74
 
                                except Exception, e:
75
 
                                        print "ERROR", e.args
76
 
 
77
 
        def geterror (self):
78
 
                return self._error
79
 
 
80
 
        def run(self):
81
 
                i = 0
82
 
                apttmproot = None
83
 
                try:
84
 
                        self._apt_con.execute( \
85
 
                                "CREATE TABLE package " + \
86
 
                                "( id integer PRIMARY KEY," + \
87
 
                                "  pkgname string NOT NULL," + \
88
 
                                "  pkgdesc strong NOT NULL," + \
89
 
                                "  pkglongdesc string NOT NULL," + \
90
 
                                "  name string NOT NULL," + \
91
 
                                "  mimetype string NOT NULL," + \
92
 
                                "  architecture string NULL," + \
93
 
                                "  appid string NOT NULL," + \
94
 
                                "  distribution string NOT NULL," + \
95
 
                                "  section string NOT NULL," + \
96
 
                                "  weight integer NOT NULL," + \
97
 
                                "  filehint integer NOT NULL," + \
98
 
                                "  description integer NOT NULL," + \
99
 
                                "  manualInstallURL string NOT NULL," + \
100
 
                                "  UNIQUE (pkgname, architecture, appid, mimetype, distribution, manualInstallURL)" + \
101
 
                                ");")
102
 
 
103
 
                except:
104
 
                        print "table already exists?"
105
 
 
106
 
                try:
107
 
                        apttmproot=nppapt.setup_tmp_cache_tree(self._configroot)
108
 
 
109
 
                        arch_arr = archs.split(" ")
110
 
                        rel_arr = releases.split(" ")
111
 
                        for architecture in arch_arr:
112
 
                                for rel in rel_arr:
113
 
                                        npp_info_entries = nppapt.get_npp_entries_for_arch_and_distribution(apttmproot, architecture, rel)
114
 
                                        self.redo_arch_rel_data(architecture, rel, npp_info_entries)
115
 
                                        self.add_extra_data(architecture, rel)
116
 
 
117
 
                finally:
118
 
                        if not apttmproot is None:
119
 
                                nppapt.tear_down_tmp_cache(apttmproot)
120
 
 
121
 
 
122
 
 
123
 
 
124
 
 
125
 
 
126
 
dbfile="/tmp/apt-plugins.sqlite"
127
 
apt_con = sqlite3.connect(dbfile)
128
 
updater = AptPluginDbUpdater(apt_con, "./")
129
 
updater.run()
130
 
apt_con.commit() 
131
 
apt_con.close()