diff options
author | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2014-08-08 15:42:03 +0000 |
---|---|---|
committer | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2014-08-08 15:48:53 +0000 |
commit | 4bc4a193a87565bc027b1aa18185bd0502633b16 (patch) | |
tree | 0565c3408227d7422bd77fccb618887f931b8a64 /morphlib/morphology.py | |
parent | d69df54e580cbd75d0e4a3b8ef28e7b1feb6030b (diff) | |
download | morph-4bc4a193a87565bc027b1aa18185bd0502633b16.tar.gz |
Rename morph3 to morphologybaserock/adamcoldrick/remove-morph2
Instead of leaving morph3 with a potentially confusing name, rename it
to `morphology` since it is now the only implementation of the
Morphology class.
Diffstat (limited to 'morphlib/morphology.py')
-rw-r--r-- | morphlib/morphology.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/morphlib/morphology.py b/morphlib/morphology.py new file mode 100644 index 00000000..a91ff390 --- /dev/null +++ b/morphlib/morphology.py @@ -0,0 +1,55 @@ +# Copyright (C) 2013-2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# =*= License: GPL-2 =*= + + +import UserDict + +import morphlib + + +class Morphology(UserDict.IterableUserDict): + + '''A container for a morphology, plus its metadata. + + A morphology is, basically, a dict. This class acts as that dict, + plus stores additional metadata about the morphology, such as where + it came from, and the ref that was used for it. It also has a dirty + attribute, to indicate whether the morphology has had changes done + to it, but does not itself set that attribute: the caller has to + maintain the flag themselves. + + This class does NO validation of the data, nor does it parse the + morphology text, or produce a textual form of itself. For those + things, see MorphologyLoader. + + ''' + + def __init__(self, *args, **kwargs): + UserDict.IterableUserDict.__init__(self, *args, **kwargs) + self.repo_url = None + self.ref = None + self.filename = None + self.dirty = None + + def get_commands(self, which): + '''Return the commands to run from a morphology or the build system''' + if self.get(which, None) is None: + attr = '_'.join(which.split('-')) + bs = morphlib.buildsystem.lookup_build_system(self['build-system']) + return getattr(bs, attr) + else: + return self[which] |