<s> import os <EOL> import glob <EOL> import re <EOL> class XFormInstanceFS ( object ) : <EOL> def __init__ ( self , filepath ) : <EOL> self . path = filepath <EOL> self . directory , self . filename = os . path . split ( self . path ) <EOL> self . xform_id = re . sub ( "<STR_LIT>" , "<STR_LIT>" , self . filename ) <EOL> @ property <EOL> def photos ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> available_photos = glob . glob ( os . path . join ( self . directory , "<STR_LIT>" ) ) <EOL> self . _photos = [ ] <EOL> for photo_path in available_photos : <EOL> _pdir , photo = os . path . split ( photo_path ) <EOL> if self . xml . find ( photo ) > <NUM_LIT:0> : <EOL> self . _photos . append ( photo_path ) <EOL> return self . _photos <EOL> @ property <EOL> def metadata_directory ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> instances_dir = os . path . join ( <EOL> self . directory , "<STR_LIT:..>" , "<STR_LIT:..>" , "<STR_LIT>" ) <EOL> metadata_directory = os . path . join ( <EOL> self . directory , "<STR_LIT:..>" , "<STR_LIT:..>" , "<STR_LIT>" ) <EOL> if os . path . exists ( instances_dir ) and os . path . exists ( <EOL> metadata_directory ) : <EOL> self . _metadata_directory = os . path . abspath ( metadata_directory ) <EOL> else : <EOL> self . _metadata_directory = False <EOL> return self . _metadata_directory <EOL> @ property <EOL> def xml ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> with open ( self . path , '<STR_LIT:r>' ) as f : <EOL> self . _xml = f . read ( ) <EOL> return self . _xml <EOL> @ classmethod <EOL> def is_valid_instance ( cls , filepath ) : <EOL> if not filepath . endswith ( "<STR_LIT>" ) : <EOL> return False <EOL> with open ( filepath , '<STR_LIT:r>' ) as ff : <EOL> fxml = ff . read ( ) . strip ( ) <EOL> if fxml . startswith ( '<STR_LIT>' ) : <EOL> return True <EOL> if '<STR_LIT>' in fxml : <EOL> return True <EOL> return False <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % self . xform_id </s>
