~roadmr/ubuntu/precise/checkbox/0.13.1

« back to all changes in this revision

Viewing changes to checkbox/lib/conversion.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif
  • Date: 2009-01-20 18:55:20 UTC
  • Revision ID: james.westby@ubuntu.com-20090120185520-s18m2hninrt53fki
Tags: 0.5
* New upstream version:
  * Added concept of hyper text view to display clickable links.
  * Added concept of properties to components.
  * Added pci information to launchpad report.
  * Added dmi information to launchpad report.
  * Added text area to keyboard test.
  * Removed sourcing of base postrm script.
  * Updated translations from Launchpad.
* Fixed handling of interrupt signal (LP: #327810)
* Fixed display of text in graphical interface (LP: #240374)
* Fixed support for regexes in blacklist and whitelist (LP: #327177)
* Fixed opening of subunit log file (LP: #325737)
* Fixed internet test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
# Copyright (c) 2008 Canonical
3
 
#
4
 
# Written by Marc Tardif <marc@interunion.ca>
5
 
#
6
2
# This file is part of Checkbox.
7
3
#
 
4
# Copyright 2008 Canonical Ltd.
 
5
#
8
6
# Checkbox is free software: you can redistribute it and/or modify
9
7
# it under the terms of the GNU General Public License as published by
10
8
# the Free Software Foundation, either version 3 of the License, or
44
42
        ("ghz?", 1024 * 1024 * 1024),
45
43
        ("thz?", 1024 * 1024 * 1024 * 1024))
46
44
 
47
 
    for regex, conversion in conversion_table:
48
 
        match = re.match("^%s$" % regex, value, re.IGNORECASE)
49
 
        if match:
50
 
            value = conversion(match)
51
 
            if len(match.groups()) < 2:
52
 
                return value
53
 
 
54
 
            unit = match.group(2)
55
 
            for regex, multiplier in multiplier_table:
56
 
                match = re.match("^%s$" % regex, unit, re.IGNORECASE)
57
 
                if match:
58
 
                    value *= multiplier
 
45
    if isinstance(value, basestring):
 
46
        for regex, conversion in conversion_table:
 
47
            match = re.match("^%s$" % regex, value, re.IGNORECASE)
 
48
            if match:
 
49
                value = conversion(match)
 
50
                if len(match.groups()) < 2:
59
51
                    return value
60
 
            else:
61
 
                raise Exception, "Unknown multiplier: %s" % unit
 
52
 
 
53
                unit = match.group(2)
 
54
                for regex, multiplier in multiplier_table:
 
55
                    match = re.match("^%s$" % regex, unit, re.IGNORECASE)
 
56
                    if match:
 
57
                        value *= multiplier
 
58
                        return value
 
59
                else:
 
60
                    raise Exception, "Unknown multiplier: %s" % unit
62
61
 
63
62
    return value
64
63