~ubuntu-branches/ubuntu/lucid/bleachbit/lucid

« back to all changes in this revision

Viewing changes to bleachbit/Update.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-10-22 21:49:11 UTC
  • mfrom: (1.1.12 upstream) (0.6.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091022214911-splx3epgkuhr48jb
Tags: 0.7.0-1
* New upstream release.
* debian/patches/GUI_relative_imports.patch:
  - Refreshed for new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
## You should have received a copy of the GNU General Public License
18
18
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
 
 
20
 
 
21
 
20
22
"""
21
23
Check for updates via the Internet
22
24
"""
23
25
 
 
26
 
24
27
import platform
25
28
import socket
26
29
import sys
27
30
import traceback
 
31
import unittest
28
32
import urllib2
29
33
import xml.dom.minidom
30
34
 
31
35
import Common
32
36
 
33
37
 
 
38
 
34
39
def user_agent():
35
40
    """Return the user agent string"""
36
41
    __platform = platform.system() # Linux or Windows
37
42
    __os = platform.uname()[2] # e.g., 2.6.28-12-generic or XP
38
43
    if sys.platform == "win32":
39
 
        # Python 2.5.4 shows uname()[2) as Vista on Windows 7
 
44
        # misleading: Python 2.5.4 shows uname()[2] as Vista on Windows 7
40
45
        __os = platform.uname()[3][0:3] # 5.1 = Windows XP, 6.0 = Vista, 6.1 = 7
41
 
    if sys.platform == 'linux2':
42
 
        dist = platform.dist()
43
 
        __os = dist[0] + '/' + dist[1] + '-' + dist[2]
 
46
    elif sys.platform == 'linux2':
 
47
        dist = platform.dist() 
 
48
        # example: ('fedora', '11', 'Leonidas')
 
49
        # example: ('', '', '') for Arch Linux
 
50
        if 0 < len(dist[0]):
 
51
            __os = dist[0] + '/' + dist[1] + '-' + dist[2]
 
52
    elif sys.platform[:6] == 'netbsd':
 
53
        __sys = platform.system()
 
54
        mach = platform.machine()
 
55
        rel = platform.release()
 
56
        __os = __sys + '/' + mach+ ' '  + rel
44
57
    __locale = ""
45
58
    try:
46
59
        import locale
63
76
 
64
77
    def get_update_info_url(self):
65
78
        """Return the URL with information about the update.
66
 
        If no update is available, URL may be none."""
 
79
        If no update is available, URL may be None."""
67
80
        return self.update_info_url
68
81
 
69
82
 
72
85
        opener = urllib2.build_opener()
73
86
        opener.addheaders = [('User-Agent', user_agent())]
74
87
        socket.setdefaulttimeout(Common.socket_timeout)
 
88
        handle = opener.open(Common.update_check_url)
 
89
        doc = handle.read()
75
90
        try:
76
 
            handle = opener.open(Common.update_check_url)
77
 
            dom = xml.dom.minidom.parse(handle)
 
91
            dom = xml.dom.minidom.parseString(doc)
78
92
        except:
79
 
            print _("Error when checking for updates: "), str(sys.exc_info()[1])
80
 
            return False
 
93
            print doc
 
94
            raise
81
95
        elements = dom.getElementsByTagName("url")
82
96
        if 0 == len(elements):
83
97
            self.update_available = False
87
101
        dom.unlink()
88
102
        return self.update_available
89
103
 
90
 
import unittest
91
104
 
92
105
class TestUpdate(unittest.TestCase):
93
106
    """Unit tests for module Update"""
102
115
 
103
116
        # test failure
104
117
        Common.update_check_url = "http://www.surelydoesnotexist.com/foo"
105
 
        self.assertEqual(update.is_update_available(), False)
 
118
        self.assertRaises(urllib2.URLError, update.is_update_available)
106
119
 
107
120
 
108
121
    def test_user_agent(self):