~gary-lasker/software-center/christhehorton-reviews-crash-fix-lp912855

« back to all changes in this revision

Viewing changes to softwarecenter/utils.py

merged the reviews branch into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
                   
43
43
LOG = logging.getLogger("softwarecenter.utils")
44
44
 
 
45
 
45
46
class ExecutionTime(object):
46
47
    """
47
48
    Helper that can be used in with statements to have a simple
145
146
    if inside_p:
146
147
        yield "</p>"
147
148
 
 
149
def get_parent_xid(widget):
 
150
    while widget.get_parent():
 
151
        widget = widget.get_parent()
 
152
    return widget.window.xid
 
153
 
 
154
def get_language():
 
155
    """Helper that returns the current language
 
156
    """
 
157
    import locale
 
158
    # those languages need the full language-code, the other ones
 
159
    # can be abbreved
 
160
    FULL = ["pt_BR", 
 
161
            "zh_CN", "zh_TW"]
 
162
    (language, encoding) = locale.getlocale()
 
163
    if language in FULL:
 
164
        return language
 
165
    return language.split("_")[0]
 
166
 
148
167
def get_http_proxy_string_from_gconf():
149
168
    """Helper that gets the http proxy from gconf
150
169
 
182
201
    p = re.compile("\&\#x(\d\d\d\d);")
183
202
    return p.sub(r"\u\1", s).decode("unicode-escape")
184
203
    
 
204
def version_compare(a, b):
 
205
    return apt_pkg.version_compare(a, b)
 
206
 
 
207
def upstream_version_compare(a, b):
 
208
    return apt_pkg.version_compare(apt_pkg.upstream_version(a),
 
209
                                   apt_pkg.upstream_version(b))
 
210
 
 
211
def upstream_version(v):
 
212
    return apt_pkg.upstream_version(v)
 
213
 
185
214
def unescape(text):
186
215
    """
187
216
    unescapes the given text
267
296
            if self.tmpdir is None:
268
297
                self.tmpdir = tempfile.mkdtemp(prefix="software-center-")
269
298
            dest_file_path = os.path.join(self.tmpdir, uri_to_filename(url))
 
299
 
270
300
        self.url = url
271
301
        self.dest_file_path = dest_file_path
272
302
        
284
314
        try:
285
315
            result = f.query_info_finish(result)
286
316
            self.emit('image-url-reachable', True)
287
 
            self.LOG.debug("image reachablee %s" % self.url)
 
317
            self.LOG.debug("image reachable %s" % self.url)
288
318
            # url is reachable, now download the icon file
289
319
            f.load_contents_async(self._icon_download_complete_cb)
290
320
        except glib.GError, e: