~vorlon/ubuntu/saucy/gourmet/trunk

« back to all changes in this revision

Viewing changes to src/lib/convert.py

  • Committer: Bazaar Package Importer
  • Author(s): Rolf Leggewie
  • Date: 2009-01-12 23:03:28 UTC
  • mfrom: (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090112230328-wnuqqte22uk3981b
Tags: 0.14.3-2
Conflict with python-pysqlite >= 2.5 which when installed crashes 
gourmet at startup. (Closes: #507382) and python-sqlalchemy >= 0.5.
Both restrictions should eventually be relaxed when upstream has
made the code compatible with the newer libs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
class Converter:
41
41
 
 
42
    __single = None
 
43
 
42
44
    unit_to_seconds = {
43
45
    'seconds':1,
44
46
    'minutes':60,
71
73
                  ]
72
74
    
73
75
    def __init__(self):
 
76
        if Converter.__single: raise Converter.__single
 
77
        else: Converter.__single = self
74
78
        self.create_conv_table()
75
79
        self.create_density_table()
76
80
        self.create_cross_unit_table()
530
534
                    if n: seconds += n * conv
531
535
                    num = []
532
536
        if seconds: return seconds
533
 
    
 
537
 
 
538
def get_converter ():
 
539
    try:
 
540
        return Converter()
 
541
    except Converter, c:
 
542
        return c
534
543
 
535
544
# Each of our time formatting functions takes two arguments, which
536
545
# allows us to handle fractions in the outside world
953
962
if __name__ == '__main__' and False:
954
963
    class InteractiveConverter:
955
964
        def __init__ (self):
956
 
            self.c = Converter()
 
965
            self.c = get_converter()
957
966
            self.options = {'Convert':self.converter,
958
967
                            'Add':self.adder,
959
968
                            'Adjust':self.adjuster,