[hg] galaxy 1518: Add a wrapper for metadata inside of DatasetFi...
details: http://www.bx.psu.edu/hg/galaxy/rev/0f735b21dc12 changeset: 1518:0f735b21dc12 user: Dan Blankenberg <dan@bx.psu.edu> date: Thu Sep 18 16:48:29 2008 -0400 description: Add a wrapper for metadata inside of DatasetFilenameWrapper to allow proper string substitution in commandline and templates. 2 file(s) affected in this change: lib/galaxy/datatypes/metadata.py lib/galaxy/tools/__init__.py diffs (56 lines): diff -r 1d326855ba89 -r 0f735b21dc12 lib/galaxy/datatypes/metadata.py --- a/lib/galaxy/datatypes/metadata.py Thu Sep 18 15:41:23 2008 -0400 +++ b/lib/galaxy/datatypes/metadata.py Thu Sep 18 16:48:29 2008 -0400 @@ -211,6 +211,9 @@ elif not isinstance(value, list): MetadataParameter.__setattr__(self, name, [value]) + def __iter__( self ): + return iter( self.value ) + def __str__(self): if self.value in [None, []]: return str(self.spec.no_value) diff -r 1d326855ba89 -r 0f735b21dc12 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py Thu Sep 18 15:41:23 2008 -0400 +++ b/lib/galaxy/tools/__init__.py Thu Sep 18 16:48:29 2008 -0400 @@ -1177,6 +1177,31 @@ Wraps a dataset so that __str__ returns the filename, but all other attributes are accessible. """ + + class MetadataWrapper: + """ + Wraps a Metadata Collection to return MetadataParameters wrapped according to the metadata spec. + Methods implemented to match behavior of a Metadata Collection. + """ + def __init__( self, metadata ): + self.metadata = metadata + def __getattr__( self, name ): + rval = self.metadata.get( name, None ) + if name in self.metadata.spec: + rval = self.metadata.spec[name].wrap( rval, self.metadata.parent ) + return rval + def __nonzero__( self ): + return self.metadata.__nonzero__() + def __iter__( self ): + return self.metadata.__iter__() + def get( self, key, default=None ): + try: + return getattr( self, key ) + except: + return default + def items( self ): + return iter( [ ( k, self.get( k ) ) for k, v in self.metadata.items() ] ) + def __init__( self, dataset, datatypes_registry = None, tool = None, name = None ): if not dataset: try: @@ -1187,6 +1212,7 @@ self.dataset = NoneDataset( datatypes_registry = datatypes_registry, ext = ext ) else: self.dataset = dataset + self.metadata = self.MetadataWrapper( dataset.metadata ) def __str__( self ): return self.dataset.file_name def __getattr__( self, key ):
participants (1)
-
gregļ¼ scofield.bx.psu.edu