~ubuntu-branches/ubuntu/wily/lubuntu-software-center/wily

« back to all changes in this revision

Viewing changes to .pc/91_choosed_category_fix.patch/src/threadingops.py

  • Committer: Package Import Robot
  • Author(s): Julien Lavergne
  • Date: 2012-03-09 14:21:53 UTC
  • Revision ID: package-import@ubuntu.com-20120309142153-0fcs9hy8yonx9me1
Tags: 0.0.4-0ubuntu3
* debian/patches:
 - 91_choosed_category_fix.patch: From upstream, fix crashed with
   AttributeError in get_func() (LP: #926266)
 - 92_local_tmp_variable.patch: From upstream, fix crashed with
   UnboundLocalError in getdeps() (LP: #942944)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding:UTF-8 -*-
 
3
#       Copyright (c) Stephen Smally <stephen.smally@gmail.com>
 
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
 
16
#       along with this program; if not, write to the Free Software
 
17
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
18
#       MA 02110-1301, USA.
 
19
#  
 
20
 
 
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
 
27
import control
 
28
import os
 
29
from xdg import DesktopEntry as DE
 
30
from aptdaemon import client, gtk3widgets
 
31
import gettext
 
32
 
 
33
_ = gettext.gettext
 
34
 
 
35
client = client.AptClient()
 
36
dialog = gtk3widgets.AptProgressDialog(debconf=True)
 
37
 
 
38
control.__init__()
 
39
 
 
40
import sqlite3
 
41
db = sqlite3.Connection(control.controller.db_path+"lsc_packages.db")
 
42
cursor = db.cursor()
 
43
 
 
44
class append_packages:
 
45
    def __init__(self, app, category, status, model, showboth):
 
46
        control.__init__()
 
47
        self.app = app
 
48
        self.category = category
 
49
        self.status = status
 
50
        self.model = model
 
51
        self.sortkey = 0
 
52
        self.showboth = showboth
 
53
    
 
54
    def run(self):
 
55
        '''Append the packages to the given Gtk.ListStore'''
 
56
        self.status_dict = {
 
57
        0: "",
 
58
        1: "",
 
59
        2: "",
 
60
        4: "",
 
61
        5: "",
 
62
        6: Gtk.STOCK_YES
 
63
        }
 
64
        x = 0
 
65
        print("sensitive!")
 
66
        if control.controller.expert_mode:
 
67
            id = 1
 
68
        else:
 
69
            id = 0
 
70
        
 
71
        if self.showboth:
 
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))
 
74
        
 
75
        else:
 
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))
 
78
        
 
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)
 
82
 
 
83
def get_categories():
 
84
    categories = {}
 
85
    cat_parser = RawConfigParser()
 
86
    if os.path.isfile(os.path.join("data", "categories.ini")):
 
87
        cat = open(os.path.join("data", "categories.ini"))
 
88
    else:
 
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]
 
97
    return categories
 
98
 
 
99
def getdesc(pkg):
 
100
    for items in cursor.execute("SELECT desc FROM packages WHERE pkg_name='%s'" % pkg):
 
101
        return items[0]
 
102
 
 
103
def getshortdesc(pkg):
 
104
    for items in cursor.execute("SELECT comment FROM packages WHERE pkg_name='%s'" % pkg):
 
105
        return items[0]
 
106
 
 
107
def getdeps(pkg):
 
108
    for item in cursor.execute("SELECT deps FROM packages WHERE pkg_name='%s'" % pkg):
 
109
        tmp = item[0]
 
110
    return tmp.split(";")
 
111
 
 
112
def getrecs(pkg):
 
113
    for item in cursor.execute("SELECT recs FROM packages WHERE pkg_name='%s'" % pkg):
 
114
        tmp = item[0]
 
115
    return tmp.split(";")
 
116
 
 
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()
 
120
    else:
 
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])):
 
124
        try:
 
125
            scrot_buf = GdkPixbuf.Pixbuf.new_from_file_at_size("/".join([path, pkg]), 250, 250)
 
126
            image.set_from_pixbuf(scrot_buf)
 
127
        except: pass
 
128
 
 
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()
 
132
    else:
 
133
        response = os.popen(" ".join(["python", "scripts/lubuntu-software-center-download-review", pkg, path])).read()
 
134
    return path+pkg
 
135
 
 
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
 
148
            text.props.xpad = 10
 
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)
 
157
 
 
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")
 
163
    dialog.run()
 
164
 
 
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")
 
170
    dialog.run()
 
171
 
 
172
def get_if_apt_lies(pkg):
 
173
    '''test if the apt cache lies'''
 
174
    result = os.system("apt-get -s install %s" % pkg)
 
175
    if result == 0:
 
176
        # Apt Cache lies, we can install it!
 
177
        return True
 
178
    else:
 
179
        # It's true, damaged packages
 
180
        return False
 
181
 
 
182
def finish_trans(transaction, exit_status, root, inst):
 
183
    if exit_status == "exit-success":
 
184
        dialog.hide()
 
185
        print("success")
 
186
        if inst:
 
187
            notify("installed")
 
188
        else:
 
189
            notify("removed")
 
190
        root.choosed_page = 1
 
191
        root.refresh_system_call()
 
192
    else:
 
193
        dialog.hide()
 
194
        finishdialog = gtkwidgets.AptErrorDialog(error=transaction.error)
 
195
        finishdialog.run()
 
196
        print("failed")
 
197