1
by Michael Vogt
initial version of update-app-install based on xapian |
1 |
#!/usr/bin/python
|
85
by Michael Vogt
update COPYRIGHT to GPL-3 |
2 |
# Copyright (C) 2009 Canonical
|
3 |
#
|
|
4 |
# Authors:
|
|
5 |
# Michael Vogt
|
|
6 |
#
|
|
7 |
# This program is free software; you can redistribute it and/or modify it under
|
|
8 |
# the terms of the GNU General Public License as published by the Free Software
|
|
325
by Michael Vogt
update license to GPLv3 |
9 |
# Foundation; version 3.
|
85
by Michael Vogt
update COPYRIGHT to GPL-3 |
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
# details.
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License along with
|
|
17 |
# this program; if not, write to the Free Software Foundation, Inc.,
|
|
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
1
by Michael Vogt
initial version of update-app-install based on xapian |
19 |
|
1864.2.23
by Alex Eftimie
one more step, trying to fix channels list and db populate |
20 |
# We have to import Gio before everything, for dynamic PK to work.
|
21 |
try: |
|
22 |
from gi.repository import Gio |
|
23 |
except: pass |
|
24 |
||
5
by Michael Vogt
README: |
25 |
import locale |
407.1.6
by Michael Vogt
* utils/update-software-center: |
26 |
import gettext |
1
by Michael Vogt
initial version of update-app-install based on xapian |
27 |
import logging |
28 |
import os |
|
407.1.6
by Michael Vogt
* utils/update-software-center: |
29 |
import os.path |
56
by Michael Vogt
* AppCenter/enums.py: |
30 |
import sys |
370
by Michael Vogt
add a small delay between dubs rebuild signal and actual rebuild |
31 |
import time |
1
by Michael Vogt
initial version of update-app-install based on xapian |
32 |
import xapian |
369
by Michael Vogt
* utils/update-software-center: |
33 |
|
407.1.7
by Michael Vogt
utils/update-software-center: use optparse, add debug option |
34 |
from optparse import OptionParser |
35 |
||
369
by Michael Vogt
* utils/update-software-center: |
36 |
from softwarecenter.enums import * |
1494
by Michael Vogt
releasing version 3.1.17.1 |
37 |
from softwarecenter.paths import XAPIAN_BASE_PATH |
369
by Michael Vogt
* utils/update-software-center: |
38 |
from softwarecenter.db.update import rebuild_database |
1806
by Michael Vogt
add contrib appstream.xml, add support for update-software-center --appstream-xml-path |
39 |
import softwarecenter.paths |
40 |
||
369
by Michael Vogt
* utils/update-software-center: |
41 |
# dbus may not be available during a upgrade so we
|
42 |
# only set it up if its there
|
|
43 |
try: |
|
44 |
import dbus |
|
45 |
import dbus.service |
|
1945.1.1
by Michael Vogt
port to gir for gobject/glib in tests/ and utils/ |
46 |
from gi.repository import GLib, GObject |
369
by Michael Vogt
* utils/update-software-center: |
47 |
from dbus.mainloop.glib import DBusGMainLoop |
1945.1.1
by Michael Vogt
port to gir for gobject/glib in tests/ and utils/ |
48 |
except ImportError as e: |
49 |
logging.warn("failure to import: '%s'" % e) |
|
369
by Michael Vogt
* utils/update-software-center: |
50 |
|
370
by Michael Vogt
add a small delay between dubs rebuild signal and actual rebuild |
51 |
# add a bit of extra time between sending the "we-rebuild-the-db-now"
|
52 |
# signal and the actual rebuilding to help the applications to shutdown
|
|
53 |
# the DB access
|
|
54 |
APP_CATCHUP_DELAY = 2 |
|
1
by Michael Vogt
initial version of update-app-install based on xapian |
55 |
|
407.1.8
by Michael Vogt
trigger on the right dir name |
56 |
# the language pack directory that we need for the triggers checking
|
57 |
LANGPACKDIR = "/usr/share/locale-langpack" |
|
58 |
||
1750.1.1
by Aaron Peachey
* utils/update-software-center, utils/update-software-center-agent |
59 |
logging.basicConfig(level=logging.INFO) |
1807
by Michael Vogt
utils/update-software-center: fix --debug output |
60 |
LOG = logging.getLogger("softwarecenter.db.update") |
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
61 |
|
330
by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648) |
62 |
class UpdateSoftwarecenterDbus(dbus.service.Object): |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
63 |
"""
|
330
by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648) |
64 |
This is a helper to provide the UpdateSoftwarecenterIFace
|
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
65 |
"""
|
66 |
def __init__(self, bus_name, |
|
330
by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648) |
67 |
object_path='/com/ubuntu/Softwarecenter'): |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
68 |
dbus.service.Object.__init__(self, bus_name, object_path) |
69 |
||
330
by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648) |
70 |
@dbus.service.method('com.ubuntu.Softwarecenter') |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
71 |
def IsRebuilding(self): |
72 |
return True |
|
330
by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648) |
73 |
@dbus.service.signal(dbus_interface='com.ubuntu.Softwarecenter', |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
74 |
signature='b') |
75 |
def DatabaseRebuilding(self, isRebuilding): |
|
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
76 |
LOG.debug("Sending DatabaseRebuilding signal '%s'" % isRebuilding) |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
77 |
|
369
by Michael Vogt
* utils/update-software-center: |
78 |
|
1
by Michael Vogt
initial version of update-app-install based on xapian |
79 |
if __name__ == "__main__": |
175
by Michael Vogt
* utils/update-software-store: |
80 |
try: |
81 |
locale.setlocale(locale.LC_ALL, "") |
|
82 |
except Exception, e: |
|
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
83 |
LOG.warn("setlocale failed with '%s'" % e) |
175
by Michael Vogt
* utils/update-software-store: |
84 |
|
407.1.7
by Michael Vogt
utils/update-software-center: use optparse, add debug option |
85 |
# parser
|
86 |
parser = OptionParser() |
|
87 |
parser.add_option("--triggered", "", default="", |
|
88 |
help="triggered from dpkg") |
|
1804.1.2
by Alex Eftimie
use appstream app-data xmls from /usr/share-appinfo; parametrize rebuild_database; change update-software-center script for local and appstream only database updates |
89 |
parser.add_option("--local", "", action="store_true", default=False, |
90 |
help="update local database") |
|
1805
by Michael Vogt
merged lp:~alexeftimie/software-center/backend-refactor to |
91 |
parser.add_option("--appstream-only", "", action="store_true", |
92 |
default=False, |
|
1804.1.2
by Alex Eftimie
use appstream app-data xmls from /usr/share-appinfo; parametrize rebuild_database; change update-software-center script for local and appstream only database updates |
93 |
help="appstream app-info only") |
1806
by Michael Vogt
add contrib appstream.xml, add support for update-software-center --appstream-xml-path |
94 |
parser.add_option("--appstream-xml-path", "", default=None, |
95 |
help="set different appstream xml rootdir") |
|
407.1.7
by Michael Vogt
utils/update-software-center: use optparse, add debug option |
96 |
parser.add_option("--debug", "", action="store_true", default=False, |
97 |
help="show debug output") |
|
1864.2.24
by Alex Eftimie
update-software-center now has a --use-packagekit option |
98 |
parser.add_option("--use-packagekit", action="store_true", |
99 |
help="use PackageKit backend (experimental)", |
|
100 |
default=False) |
|
407.1.7
by Michael Vogt
utils/update-software-center: use optparse, add debug option |
101 |
(options, args) = parser.parse_args() |
102 |
||
407.1.8
by Michael Vogt
trigger on the right dir name |
103 |
#logging.basicConfig(level=logging.INFO)
|
407.1.7
by Michael Vogt
utils/update-software-center: use optparse, add debug option |
104 |
if options.debug: |
1549
by Michael Vogt
* utils/update-software-center: |
105 |
LOG.setLevel(logging.DEBUG) |
407.1.7
by Michael Vogt
utils/update-software-center: use optparse, add debug option |
106 |
|
1804.1.2
by Alex Eftimie
use appstream app-data xmls from /usr/share-appinfo; parametrize rebuild_database; change update-software-center script for local and appstream only database updates |
107 |
if options.local: |
108 |
if not os.path.exists('./data'): |
|
109 |
LOG.error("trying to update local database, ./data does not exist") |
|
110 |
sys.exit(-1) |
|
111 |
LOG.info("updating local database") |
|
112 |
xapian_base_path = './data' |
|
113 |
else: |
|
114 |
xapian_base_path = XAPIAN_BASE_PATH |
|
115 |
||
1805
by Michael Vogt
merged lp:~alexeftimie/software-center/backend-refactor to |
116 |
if options.appstream_only: |
1804.1.2
by Alex Eftimie
use appstream app-data xmls from /usr/share-appinfo; parametrize rebuild_database; change update-software-center script for local and appstream only database updates |
117 |
LOG.info("updating only information from app-info") |
118 |
||
1806
by Michael Vogt
add contrib appstream.xml, add support for update-software-center --appstream-xml-path |
119 |
if options.appstream_xml_path: |
120 |
softwarecenter.paths.APPSTREAM_XML_PATH = options.appstream_xml_path |
|
121 |
||
1864.2.24
by Alex Eftimie
update-software-center now has a --use-packagekit option |
122 |
if options.use_packagekit: |
123 |
LOG.info("using the PackageKit backend") |
|
124 |
softwarecenter.enums.USE_PACKAGEKIT_BACKEND = True |
|
125 |
||
407.1.7
by Michael Vogt
utils/update-software-center: use optparse, add debug option |
126 |
# check if we are dpkg triggered because of langpack change
|
127 |
# and avoid unneeded database rebuilds by checking the timestamp
|
|
128 |
# of the app-install-data mo file
|
|
407.1.8
by Michael Vogt
trigger on the right dir name |
129 |
if options.triggered and options.triggered == LANGPACKDIR: |
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
130 |
LOG.debug("triggered with '%s'" % options.triggered) |
407.1.6
by Michael Vogt
* utils/update-software-center: |
131 |
mofile = gettext.find("app-install-data") |
132 |
if not mofile: |
|
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
133 |
LOG.info("no translation information in database needed") |
407.1.6
by Michael Vogt
* utils/update-software-center: |
134 |
sys.exit(0) |
135 |
mo_time = os.path.getctime(mofile) |
|
1804.1.2
by Alex Eftimie
use appstream app-data xmls from /usr/share-appinfo; parametrize rebuild_database; change update-software-center script for local and appstream only database updates |
136 |
pathname = os.path.join(xapian_base_path, "xapian") |
407.1.6
by Michael Vogt
* utils/update-software-center: |
137 |
if os.path.exists(pathname): |
138 |
db = xapian.Database(pathname) |
|
139 |
mo_db_time = db.get_metadata("app-install-mo-time") |
|
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
140 |
LOG.debug("mo_time: %s db_mo_time: %s" % (mo_time, mo_db_time)) |
407.1.6
by Michael Vogt
* utils/update-software-center: |
141 |
if str(mo_time) == mo_db_time: |
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
142 |
LOG.info("translation information in database is up-to-date") |
407.1.6
by Michael Vogt
* utils/update-software-center: |
143 |
sys.exit(0) |
144 |
||
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
145 |
# setup dbus
|
146 |
dbus_controller = None |
|
147 |
try: |
|
148 |
DBusGMainLoop(set_as_default=True) |
|
149 |
bus = dbus.SystemBus() |
|
330
by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648) |
150 |
bus_name = dbus.service.BusName('com.ubuntu.Softwarecenter', bus) |
151 |
dbus_controller = UpdateSoftwarecenterDbus(bus_name) |
|
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
152 |
dbus_controller.DatabaseRebuilding(True) |
370
by Michael Vogt
add a small delay between dubs rebuild signal and actual rebuild |
153 |
time.sleep(APP_CATCHUP_DELAY) |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
154 |
except: |
1292
by Michael Vogt
* softwarecenter/db/update.py, utils/update-software-center: |
155 |
LOG.warn("Failed to setup dbus (ignoring)") |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
156 |
|
157 |
# rebuild and send signal when done
|
|
158 |
try: |
|
159 |
# setup path
|
|
1804.1.2
by Alex Eftimie
use appstream app-data xmls from /usr/share-appinfo; parametrize rebuild_database; change update-software-center script for local and appstream only database updates |
160 |
pathname = os.path.join(xapian_base_path, "xapian") |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
161 |
if not os.path.exists(pathname): |
162 |
os.makedirs(pathname) |
|
163 |
# rebuild the database, the default context is run to ensure
|
|
164 |
# dbus querries are processed
|
|
1398.1.1
by Aaron Peachey
output messages when 'update-software-center' is run manually by user |
165 |
print "Updating software catalog...this may take a moment." |
1805
by Michael Vogt
merged lp:~alexeftimie/software-center/backend-refactor to |
166 |
if options.appstream_only: |
1804.1.2
by Alex Eftimie
use appstream app-data xmls from /usr/share-appinfo; parametrize rebuild_database; change update-software-center script for local and appstream only database updates |
167 |
result = rebuild_database(pathname, debian_sources=False, appstream_sources=True) |
168 |
else: |
|
169 |
result = rebuild_database(pathname) |
|
170 |
if result: |
|
1398.1.1
by Aaron Peachey
output messages when 'update-software-center' is run manually by user |
171 |
print "Software catalog update was successful." |
172 |
else: |
|
173 |
print "There was a problem updating the software catalog. Please try again or check the log." |
|
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
174 |
finally: |
175 |
# signal that the xapian db is valid again
|
|
176 |
if dbus_controller: |
|
370
by Michael Vogt
add a small delay between dubs rebuild signal and actual rebuild |
177 |
time.sleep(APP_CATCHUP_DELAY) |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
178 |
dbus_controller.DatabaseRebuilding(False) |
1945.1.1
by Michael Vogt
port to gir for gobject/glib in tests/ and utils/ |
179 |
context = GObject.main_context_default() |
286
by Michael Vogt
implement dbus service that informs the GUI if the database |
180 |
while context.pending(): |
181 |
context.iteration() |