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
|
#!/usr/bin/python
# Copyright (C) 2010 Canonical
#
# Authors:
# Michael Vogt
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import apt
import locale
import gettext
import logging
import os
import os.path
import shutil
import string
import sys
import time
import xapian
import xdg.BaseDirectory
from optparse import OptionParser
from softwarecenter.enums import *
from softwarecenter.db.update import update_from_software_center_agent
import softwarecenter.log
if __name__ == "__main__":
try:
locale.setlocale(locale.LC_ALL, "")
except Exception, e:
logging.warn("setlocale failed with '%s'" % e)
# parser
parser = OptionParser()
parser.add_option("--debug", "", action="store_true", default=False,
help="show debug output")
parser.add_option("--ignore-etag", "", action="store_true", default=False,
help="update even if etag value matches")
(options, args) = parser.parse_args()
logging.basicConfig(level=logging.INFO)
if options.debug:
logging.basicConfig(level=logging.DEBUG)
softwarecenter.log.root.setLevel(level=logging.DEBUG)
# get a cache
cache = apt.Cache(memonly=True)
# setup path
pathname = XAPIAN_BASE_PATH_SOFTWARE_CENTER_AGENT+".tmp"
if not os.path.exists(pathname):
os.makedirs(pathname)
# check that we can write
if not os.access(pathname, os.W_OK):
logging.warn("Cannot write to '%s'." % pathname)
logging.warn("Please check you have the relevant permissions.")
sys.exit(1)
# get a writable DB
db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OVERWRITE)
# the following requires a http connection, so we do it in a
# seperate database
if not update_from_software_center_agent(db, cache, options.ignore_etag):
logging.debug("no updates from update-software-center-agent")
sys.exit(1)
# flush ...
db.flush()
del db
# and move into place
final_pathname = string.rsplit(pathname, ".tmp", 1)[0]
if os.path.exists(final_pathname):
shutil.rmtree(final_pathname)
os.rename(pathname, final_pathname)
|