3
# Copyright (c) Stephen Smally <stephen.smally@gmail.com>
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.
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.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
from gi.repository import Gtk
22
from gi.repository import Pango
23
from gi.repository import Gdk
24
from gi.repository import GdkPixbuf
25
from ConfigParser import RawConfigParser
26
from notify import notify
29
from xdg import DesktopEntry as DE
30
from aptdaemon import client, gtk3widgets
35
client = client.AptClient()
36
dialog = gtk3widgets.AptProgressDialog(debconf=True)
41
db = sqlite3.Connection(control.controller.db_path+"lsc_packages.db")
44
class append_packages:
45
def __init__(self, app, category, status, model, showboth):
48
self.category = category
52
self.showboth = showboth
55
'''Append the packages to the given Gtk.ListStore'''
66
if control.controller.expert_mode:
72
for items in cursor.execute("SELECT * FROM %s ORDER BY name" % (self.category)):
73
self.app.append_packages_appending(items, self.status, self.status_dict, self.model, (1, 1))
76
for items in cursor.execute("SELECT * FROM %s WHERE ID=%s ORDER BY name" % (self.category, id)):
77
self.app.append_packages_appending(items, self.status, self.status_dict, self.model, (1, 1))
79
self.app.ui.pkgs_count.set_text("%s " % len(self.model) +_("packages listed"))
80
if self.app.ui.search_pkg.search_entry.get_text() != self.app.ui.search_pkg.search_string:
81
self.app.ui.search_pkg.search_function(self.app.ui.search_pkg.search_entry.get_text(), 20)
85
cat_parser = RawConfigParser()
86
if os.path.isfile(os.path.join("data", "categories.ini")):
87
cat = open(os.path.join("data", "categories.ini"))
89
cat = open(os.path.join(control.controller.data_system_path, "categories.ini"))
90
cat_parser.readfp(cat)
91
for section in cat_parser.sections():
92
name = cat_parser.get(section, "name")
93
icon = cat_parser.get(section, "icon")
94
tags = cat_parser.get(section, "contains")
95
showboth = cat_parser.getboolean(section, "showboth")
96
categories[section] = [icon, name, showboth]
100
for items in cursor.execute("SELECT desc FROM packages WHERE pkg_name='%s'" % pkg):
103
def getshortdesc(pkg):
104
for items in cursor.execute("SELECT comment FROM packages WHERE pkg_name='%s'" % pkg):
108
for item in cursor.execute("SELECT deps FROM packages WHERE pkg_name='%s'" % pkg):
110
return tmp.split(";")
113
for item in cursor.execute("SELECT recs FROM packages WHERE pkg_name='%s'" % pkg):
115
return tmp.split(";")
117
def download_screenshot(pkg, path, image, button):
118
if os.path.isfile(os.path.join("/usr/lib/lubuntu-software-center/lubuntu-software-center-download-scrot")):
119
response = os.popen(" ".join(["python", "/usr/lib/lubuntu-software-center/lubuntu-software-center-download-scrot", pkg, path])).read()
121
response = os.popen(" ".join(["python", "scripts/lubuntu-software-center-download-scrot", pkg, path])).read()
122
button.set_visible(True)
123
if os.path.exists("/".join([path, pkg])):
125
scrot_buf = GdkPixbuf.Pixbuf.new_from_file_at_size("/".join([path, pkg]), 250, 250)
126
image.set_from_pixbuf(scrot_buf)
129
def download_review(pkg, path):
130
if os.path.isfile(os.path.join("/usr/lib/lubuntu-software-center/lubuntu-software-center-download-review")):
131
response = os.popen(" ".join(["python", "/usr/lib/lubuntu-software-center/lubuntu-software-center-download-review", pkg, path])).read()
133
response = os.popen(" ".join(["python", "scripts/lubuntu-software-center-download-review", pkg, path])).read()
136
def parse_review(pkg, path, box):
137
if os.path.exists(path+pkg+".ini"):
138
review_parser = RawConfigParser()
139
review = open(path+pkg+".ini", "r")
140
review_parser.readfp(review)
141
for reviews in review_parser.sections():
142
summary = Gtk.Label("<b>"+review_parser.get(reviews, "summary").capitalize()+"</b>")
143
summary.set_use_markup(True)
144
summary.props.xalign = 0.0
145
summary.props.xpad = 5
146
text = Gtk.Label(review_parser.get(reviews, "review_text"))
147
text.props.xalign = 0.0
149
text.set_line_wrap_mode(Pango.WrapMode.WORD)
150
text.set_line_wrap(True)
151
box.pack_start(summary, False, False, 0)
152
box.pack_start(text, False, False, 0)
153
if len(box.get_children()) == 1: # If only the Reviews title is in the box
154
summary = Gtk.Label("<b>"+_("No reviews available")+"</b>")
155
summary.set_use_markup(True)
156
box.pack_start(summary, False, False, 0)
158
def install_package(pkgs, app):
159
transaction = client.install_packages(pkgs)
160
transaction.connect("finished", finish_trans, app, True)
161
dialog.set_transaction(transaction)
162
print("running dialog")
165
def remove_package(pkgs, app):
166
transaction = client.remove_packages(pkgs)
167
transaction.connect("finished", finish_trans, app, False)
168
dialog.set_transaction(transaction)
169
print("running dialog")
172
def get_if_apt_lies(pkg):
173
'''test if the apt cache lies'''
174
result = os.system("apt-get -s install %s" % pkg)
176
# Apt Cache lies, we can install it!
179
# It's true, damaged packages
182
def finish_trans(transaction, exit_status, root, inst):
183
if exit_status == "exit-success":
190
root.choosed_page = 1
191
root.refresh_system_call()
194
finishdialog = gtkwidgets.AptErrorDialog(error=transaction.error)