2
# Copyright (C) 2010 Canonical
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
9
# Foundation; version 3.
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
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
32
import xdg.BaseDirectory
34
from optparse import OptionParser
36
from softwarecenter.enums import *
37
from softwarecenter.db.update import update_from_software_center_agent
39
if __name__ == "__main__":
41
locale.setlocale(locale.LC_ALL, "")
43
logging.warn("setlocale failed with '%s'" % e)
46
parser = OptionParser()
47
parser.add_option("--debug", "", action="store_true", default=False,
48
help="show debug output")
49
(options, args) = parser.parse_args()
51
logging.basicConfig(level=logging.INFO)
53
logging.basicConfig(level=logging.DEBUG)
56
cache = apt.Cache(memonly=True)
59
pathname = XAPIAN_BASE_PATH_SOFTWARE_CENTER_AGENT+".tmp"
60
if not os.path.exists(pathname):
63
# check that we can write
64
if not os.access(pathname, os.W_OK):
65
logging.warn("Cannot write to '%s'." % pathname)
66
logging.warn("Please check you have the relevant permissions.")
70
db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OVERWRITE)
72
# the following requires a http connection, so we do it in a
74
if not update_from_software_center_agent(db, cache):
75
logging.warn("update_from_software_center_agent_failed")
83
final_pathname = string.rsplit(pathname, ".tmp", 1)[0]
84
if os.path.exists(final_pathname):
85
shutil.rmtree(final_pathname)
86
os.rename(pathname, final_pathname)