Ignore:
Timestamp:
05/05/12 11:02:52 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Added support for saving and loading PIREPs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/pirep.py

    r102 r151  
    44
    55import const
     6import cPickle as pickle
    67
    78#------------------------------------------------------------------------------
     
    2526        some other things."""
    2627        return "[" + timeStr + "]-[" + line + "]"
     28
     29    @staticmethod
     30    def load(path):
     31        """Load a PIREP from the given path.
     32
     33        Returns the PIREP object, or None on error."""
     34        try:
     35            with open(path, "rb") as f:
     36                return pickle.load(f)
     37        except Exception, e:
     38            print "Failed loading PIREP from %s: %s" % (path, str(e))
     39            return None
    2740       
    2841    def __init__(self, gui):
     
    114127            star += self.transition
    115128        return star.upper()
     129
     130    def save(self, path):
     131        """Save the PIREP to the given file.
     132
     133        Returns whether the saving has succeeded."""
     134        try:
     135            with open(path, "wb") as f:
     136                pickle.dump(self, f)
     137            return True
     138        except Exception, e:
     139            print "Failed saving PIREP to %s: %s" % (path, str(e))
     140            return False
Note: See TracChangeset for help on using the changeset viewer.