Changeset 1459:b301cae30997

Show
Ignore:
Timestamp:
07/30/08 17:15:40 (4 months ago)
Author:
Nate Coraor <nate@bx.psu.edu>
branch:
default
Message:

Rolling back Dan's most recent commits, we'll be setting up a branch for this.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/galaxy/datatypes/images.py

    r1454 r1459  
    111111        "urlpause" :"100", 
    112112        "debug": "false", 
    113         "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'maf', 'name': 'GMAJ Output on data %s' % dataset.hid, 'info': 'Added by GMAJ', 'dbkey': dataset.dbkey, 'copy_access_from': dataset.id } ) 
     113        "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'maf', 'name': 'GMAJ Output on data %s' % dataset.hid, 'info': 'Added by GMAJ', 'dbkey': dataset.dbkey } ) 
    114114        } 
    115115        class_name = "edu.psu.bx.gmaj.MajApplet.class" 
     
    181181        "buttonlabel": "Launch LAJ", 
    182182        "title": "LAJ in Galaxy", 
    183         "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'lav', 'name': 'LAJ Output', 'info': 'Added by LAJ', 'dbkey': dataset.dbkey, 'copy_access_from': dataset.id } ), 
     183        "posturl": "history_add_to?%s" % urlencode( { 'history_id': dataset.history_id, 'ext': 'lav', 'name': 'LAJ Output', 'info': 'Added by LAJ', 'dbkey': dataset.dbkey } ), 
    184184        "noseq": "true" 
    185185        } 
  • lib/galaxy/model/__init__.py

    r1456 r1459  
    2828 
    2929class User( object ): 
    30     def __init__( self, email=None, password=None, groups = [], roles = [], default_groups = [], default_roles = [] ): 
     30    def __init__( self, email=None, password=None ): 
    3131        self.email = email 
    3232        self.password = password 
     
    3434        # Relationships 
    3535        self.histories = [] 
    36         if not groups: 
    37             groups.append( GalaxyGroup.get( GalaxyGroup.public_id ) ) 
    38             default_groups.append( groups[-1] ) 
    39             default_groups.append( self.create_private_group() ) 
    40         group_id_added = [] 
    41         for group in groups: 
    42             if group.id not in group_id_added: 
    43                 group.add_user( self ) 
    44                 group_id_added.append( group.id ) 
    45         group_id_added = [] 
    46         for group in default_groups: 
    47             if group.id not in group_id_added: 
    48                 user_group_assoc = DefaultUserGroupAssociation( self, group ) 
    49                 user_group_assoc.flush() 
    50                 group_id_added.append( group.id ) 
    51         role_id_added = [] 
    52         for role in roles: 
    53             if role.id not in role_id_added: 
    54                 role.add_user( self ) 
    55                 role_id_added.append( role.id ) 
    56         role_id_added = [] 
    57         for role in default_roles: 
    58             if role.id not in role_id_added: 
    59                 role_group_assoc = DefaultUserRoleAssociation( self, role ) 
    60                 role_group_assoc.flush() 
    61                 role_id_added.append( role.id ) 
    6236    def set_password_cleartext( self, cleartext ): 
    6337        """Set 'self.password' to the digest of 'cleartext'.""" 
     
    6640        """Check if 'cleartext' matches 'self.password' when hashed.""" 
    6741        return self.password == sha.new( cleartext ).hexdigest() 
    68     def create_private_group( self ): 
    69         #create private group 
    70         group = GalaxyGroup( self.email, priority = 10 ) 
    71         group.flush() 
    72         #create private dataset access role 
    73         role = AccessRole( "%s dataset access" % self.email, list( Dataset.access_actions.__dict__.values() ), priority = 1 ) 
    74         role.flush() 
    75         #add role to group 
    76         group.add_role( role ) 
    77          
    78         #create roles for user modification of role 
    79         user_role = AccessRole( "%s role modification" % self.email, list( AccessRole.access_actions.__dict__.values() ) ) 
    80         user_role.flush() 
    81         #add role to user 
    82         user_role.add_user( self ) 
    83         #add role to role 
    84         role.add_role( user_role ) 
    85          
    86         #create roles for user modification of group 
    87         group_role = AccessRole( "%s group modification" % self.email, list( GalaxyGroup.access_actions.__dict__.values() ) ) 
    88         group_role.flush() 
    89         #add role to group 
    90         group.add_access_role( group_role ) 
    91         #associate role and user 
    92         group_role.add_user( self ) 
    93          
    94         #add user to group 
    95         group.add_user( self ) 
    96         group.flush() 
    97         return group 
    98     def add_group( self, group ): 
    99         return group.add_user( self ) 
    100     def has_group( self, check_group ): 
    101         return bool( UserGroupAssociation.get_by( group_id = check_group.id, user_id = self.id ) ) 
    102     def has_role( self, check_role ): 
    103         return bool( UserRoleAssociation.get_by( role_id = check_role.id, user_id = self.id ) ) 
    104     def set_default_access( self, groups = None, roles = None, history = False, dataset = False ): 
    105         if groups is not None: 
    106             for assoc in self.default_groups: #this is the association not the actual group 
    107                 assoc.delete() 
    108                 assoc.flush() 
    109             for group in groups: 
    110                 assoc = DefaultUserGroupAssociation( self, group ) 
    111                 assoc.flush() 
    112         if roles is not None: 
    113             for assoc in self.default_roles: #this is the association not the actual group 
    114                 assoc.delete() 
    115                 assoc.flush() 
    116             for role in roles: 
    117                 assoc = DefaultUserRoleAssociation( self, role ) 
    118                 assoc.flush() 
    119         if history: 
    120             for history in self.histories: 
    121                 history.set_default_access( groups = groups, roles = roles, dataset = dataset ) 
    122      
     42         
    12343class Job( object ): 
    12444    """ 
     
    182102        self.dataset = dataset 
    183103 
    184 class AccessRole( object ): 
    185     dataset_actions = Bunch( VIEW = 'dataset_view', #viewing/downloading 
    186                     USE = 'dataset_use', #use in jobs 
    187                     ADD_ROLE = 'dataset_add_role', #dataset can be added to roles 
    188                     REMOVE_ROLE = 'dataset_remove_role', #dataset can be removed from roles 
    189                     ADD_GROUP = 'dataset_add_group', #dataset can be added to groups 
    190                     REMOVE_GROUP = 'dataset_remove_group' ) #dataset can be removed from groups 
    191     role_actions = Bunch( ADD_DATASET = 'role_add_dataset', #add role to dataset 
    192                     REMOVE_DATASET = 'role_remove_dataset', #remove role from dataset 
    193                     DELETE = 'role_delete', #delete a role 
    194                     MODIFY = 'role_modify', #change a role's actions, 
    195                     ADD_GROUP = 'role_add_group', #add role to a group 
    196                     REMOVE_GROUP = 'role_remove_group' ) #remove role from a group 
    197     group_actions = Bunch( ADD_DATASET = 'group_add_dataset', #add group to dataset 
    198                     REMOVE_DATASET = 'group_remove_dataset', #remove dataset from group 
    199                     DELETE = 'group_delete', #delete a group 
    200                     ADD_ROLE = 'group_add_role', #add role to group 
    201                     REMOVE_ROLE = 'group_remove_role', #remove role from group 
    202                     ADD_USER = 'group_add_user' ) #add users to group 
    203      
    204     access_actions = role_actions 
    205      
    206     def __init__( self, name, actions, priority = 0 ): 
    207         self.name = name 
    208         if not isinstance( actions, list ): 
    209             actions = [ actions ] 
    210         self.actions = actions 
    211         self.priority = priority 
    212     def add_user( self, user ): 
    213         assoc = UserRoleAssociation( user, self ) 
    214         assoc.flush() 
    215         return assoc 
    216     def add_group( self, group ): 
    217         assoc = GroupRoleAssociation( group, self ) 
    218         assoc.flush() 
    219         return assoc 
    220     def add_role( self, role ): 
    221         assoc = RoleRoleAssociation( role, self ) 
    222         assoc.flush() 
    223         return assoc 
    224     def add_dataset( self, dataset ): 
    225         assoc = RoleDatasetAssociation( self, dataset ) 
    226         assoc.flush() 
    227         return assoc 
    228  
    229 class GalaxyGroup( object ): 
    230     public_id = None 
    231     access_actions = AccessRole.group_actions 
    232     def __init__( self, name, priority = 0 ): 
    233         self.name = name 
    234         self.priority = priority 
    235     def add_user( self, user ): 
    236         assoc = UserGroupAssociation( user, self ) 
    237         assoc.flush() 
    238         return assoc 
    239     def add_role( self, role ): 
    240         return role.add_group( self ) 
    241     def add_access_role( self, role ): 
    242         assoc = GroupRoleAccessAssociation( self, role ) 
    243         assoc.flush() 
    244         return assoc 
    245     def add_dataset( self, dataset ): 
    246         assoc = GroupDatasetAssociation( self, dataset ) 
    247         assoc.flush() 
    248         return assoc 
    249  
    250 class UserGroupAssociation( object ): 
    251     def __init__( self, user, group ): 
    252         self.user = user 
    253         self.group = group 
    254  
    255 class RoleRoleAssociation( object ): 
    256     def __init__( self, role, target_role ): 
    257         self.role = role 
    258         self.target_role = target_role 
    259  
    260 class GroupRoleAccessAssociation( object ): 
    261     def __init__( self, group, role ): 
    262         self.group = group 
    263         self.role = role 
    264  
    265 class GroupRoleAssociation( object ): 
    266     def __init__( self, group, role ): 
    267         self.group = group 
    268         self.role = role 
    269  
    270 class UserRoleAssociation( object ): 
    271     def __init__( self, user, role ): 
    272         self.user = user 
    273         self.role = role 
    274  
    275 class GroupDatasetAssociation( object ): 
    276     def __init__( self, group, dataset ): 
    277         if isinstance( group, GroupDatasetAssociation ) or isinstance( group, DefaultUserGroupAssociation ) or isinstance( group, DefaultHistoryGroupAssociation ): 
    278             group = group.group 
    279         self.group = group 
    280          
    281         if isinstance( dataset, HistoryDatasetAssociation ): 
    282             dataset = dataset.dataset 
    283         self.dataset = dataset 
    284  
    285 class RoleDatasetAssociation( object ): 
    286     def __init__( self, role, dataset ): 
    287         if isinstance( role, RoleDatasetAssociation ) or isinstance( role, DefaultUserRoleAssociation ) or isinstance( role, DefaultHistoryRoleAssociation ): 
    288             role = role.role 
    289         self.role = role 
    290          
    291         if isinstance( dataset, HistoryDatasetAssociation ): 
    292             dataset = dataset.dataset 
    293         self.dataset = dataset 
    294  
    295 class DefaultUserRoleAssociation( object ): 
    296     def __init__( self, user, role ): 
    297         if isinstance( role, RoleDatasetAssociation ) or isinstance( role, DefaultUserRoleAssociation ) or isinstance( role, DefaultHistoryRoleAssociation ): 
    298             role = role.role 
    299         self.user = user 
    300         self.role = role 
    301  
    302 class DefaultUserGroupAssociation( object ): 
    303     def __init__( self, user, group ): 
    304         if isinstance( group, GroupDatasetAssociation ) or isinstance( group, DefaultUserGroupAssociation ) or isinstance( group, DefaultHistoryGroupAssociation ): 
    305             group = group.group 
    306         self.user = user 
    307         self.group = group 
    308  
    309 class DefaultHistoryRoleAssociation( object ): 
    310     def __init__( self, history, role ): 
    311         if isinstance( role, RoleDatasetAssociation ) or isinstance( role, DefaultUserRoleAssociation ) or isinstance( role, DefaultHistoryRoleAssociation ): 
    312             role = role.role 
    313         self.history = history 
    314         self.role = role 
    315  
    316 class DefaultHistoryGroupAssociation( object ): 
    317     def __init__( self, history, group ): 
    318         if isinstance( group, GroupDatasetAssociation ) or isinstance( group, DefaultUserGroupAssociation ) or isinstance( group, DefaultHistoryGroupAssociation ): 
    319             group = group.group 
    320         self.history = history 
    321         self.group = group 
    322  
    323 class Dataset( object ): 
    324     states = Bunch( NEW = 'new', 
    325                     QUEUED = 'queued', 
    326                     RUNNING = 'running', 
    327                     OK = 'ok', 
    328                     EMPTY = 'empty', 
    329                     ERROR = 'error', 
    330                     DISCARDED = 'discarded' ) 
    331     access_actions = AccessRole.dataset_actions 
    332     file_path = "/tmp/" 
    333     engine = None 
    334     def __init__( self, id=None, state=None, external_filename=None, extra_files_path=None, file_size=None, purgable=True, access_groups=[], access_roles=[] ): 
    335         self.id = id 
    336         self.state = state 
    337         self.deleted = False 
    338         self.purged = False 
    339         self.purgable = purgable 
    340         self.external_filename = external_filename 
    341         self._extra_files_path = extra_files_path 
    342         self.file_size = file_size 
    343         if access_groups or access_roles: 
    344             #self.flush() 
    345             for group in access_groups: 
    346                 group.add_dataset( self ) 
    347                 group.flush() 
    348             for role in access_roles: 
    349                 role.add_dataset( self ) 
    350                 role.flush() 
    351     def get_file_name( self ): 
    352         if not self.external_filename: 
    353             assert self.id is not None, "ID must be set before filename used (commit the object)" 
    354             # First try filename directly under file_path 
    355             filename = os.path.join( self.file_path, "dataset_%d.dat" % self.id ) 
    356             # Only use that filename if it already exists (backward compatibility), 
    357             # otherwise construct hashed path 
    358             if not os.path.exists( filename ): 
    359                 dir = os.path.join( self.file_path, *directory_hash_id( self.id ) ) 
    360                 # Create directory if it does not exist 
    361                 try: 
    362                     os.makedirs( dir ) 
    363                 except OSError, e: 
    364                     # File Exists is okay, otherwise reraise 
    365                     if e.errno != errno.EEXIST: 
    366                         raise 
    367                 # Return filename inside hashed directory 
    368                 return os.path.abspath( os.path.join( dir, "dataset_%d.dat" % self.id ) ) 
    369         else: 
    370             filename = self.external_filename 
    371         # Make filename absolute 
    372         return os.path.abspath( filename ) 
    373              
    374     def set_file_name ( self, filename ): 
    375         if not filename: 
    376             self.external_filename = None 
    377         else: 
    378             self.external_filename = filename 
    379          
    380     file_name = property( get_file_name, set_file_name ) 
    381      
    382     @property 
    383     def extra_files_path( self ): 
    384         if self._extra_files_path:  
    385             path = self._extra_files_path 
    386         else: 
    387             path = os.path.join( self.file_path, "dataset_%d_files" % self.id ) 
    388             #only use path directly under self.file_path if it exists 
    389             if not os.path.exists( path ): 
    390                 path = os.path.join( os.path.join( self.file_path, *directory_hash_id( self.id ) ), "dataset_%d_files" % self.id ) 
    391         # Make path absolute 
    392         return os.path.abspath( path ) 
    393      
    394     def get_size( self ): 
    395         """Returns the size of the data on disk""" 
    396         if self.file_size: 
    397             return self.file_size 
    398         else: 
    399             try: 
    400                 return os.path.getsize( self.file_name ) 
    401             except OSError: 
    402                 return 0 
    403     def set_size( self ): 
    404         """Returns the size of the data on disk""" 
    405         try: 
    406             self.file_size = os.path.getsize( self.file_name ) 
    407         except OSError: 
    408             self.file_size = 0 
    409     def has_data( self ): 
    410         """Detects whether there is any data""" 
    411         return self.get_size() > 0 
    412     def mark_deleted( self, include_children=True ): 
    413         self.deleted = True 
    414     def allow_action( self, user, action ): 
    415         """Returns true when user has permission to perform an action""" 
    416          
    417         #if dataset is in public group, we always return true for viewing and using 
    418         #this may need to change when the ability to alter groups and roles is allowed 
    419         if action in [ self.access_actions.USE, self.access_actions.VIEW ] and GroupDatasetAssociation.get_by( group_id = GalaxyGroup.public_id, dataset_id = self.id ): 
    420             return True 
    421         elif user is not None: 
    422             #loop through permissions and if allowed return true: 
    423             #check roles associated directly with dataset first 
    424             for role_dataset_assoc in self.roles: 
    425                 if action in role_dataset_assoc.role.actions and user.has_role( role_dataset_assoc.role ): 
    426                     return True 
    427             #check roles associated with dataset through groups 
    428             for group_dataset_assoc in self.groups: 
    429                 if user.has_group( group_dataset_assoc.group ): 
    430                     for group_role_assoc in group_dataset_assoc.group.roles: 
    431                         if action in group_role_assoc.role.actions: 
    432                             return True 
    433         return False #no user and dataset not in public group, or user lacks permission 
    434     def guess_derived_groups_roles( self, other_datasets = [] ): 
    435         """Returns a list of output roles and groups based upon itself and provided datasets""" 
    436         if not other_datasets: 
    437             return [ data_group_assoc.group for data_group_assoc in self.groups ], [ data_role_assoc.role for data_role_assoc in self.roles ] 
    438         access_roles = None 
    439         priority_access_role = None 
    440         access_groups = None 
    441         priority_access_group = None 
    442         for dataset in [ self ] + other_datasets: 
    443             #determine access roles and groups for output datasets 
    444             #roles and groups for output dataset is the intersection across all inputs 
    445             #if we end up with no intersection between inputs, then we rely on priorities 
    446             if isinstance( dataset, HistoryDatasetAssociation ): 
    447                 dataset = dataset.dataset 
    448             roles = [ data_role_assoc.role for data_role_assoc in dataset.roles ] 
    449             for role in roles: 
    450                 if priority_access_role is None or priority_access_role.priority < role.priority: 
    451                     priority_access_role = role 
    452             groups = [ data_group_assoc.group for data_group_assoc in dataset.groups ] 
    453             for group in groups: 
    454                 if priority_access_group is None or priority_access_group.priority < group.priority: 
    455                     priority_access_group = group 
    456             if access_roles is None: 
    457                 access_roles = set( roles ) 
    458                 access_groups = set( groups ) 
    459             else: 
    460                 access_roles.intersection_update( set( roles ) ) 
    461                 access_groups.intersection_update( set( groups ) ) 
    462          
    463         #complete lists for output dataset access 
    464         if access_roles: 
    465             access_roles = list( access_roles ) 
    466         else: 
    467             access_roles = [] 
    468         if access_groups: 
    469             access_groups = list( access_groups) 
    470         else: 
    471             access_groups = [] 
    472         #if we have no roles or groups left after intersection, 
    473         #take the highest priority group or role 
    474         if not access_roles and not access_groups: 
    475             if priority_access_role and priority_access_group: 
    476                 if priority_access_group.priority == priority_access_role.priority: 
    477                     access_groups = [ priority_access_group ] 
    478                     access_roles = [ priority_access_role ] 
    479                 elif priority_access_group.priority > priority_access_role.priority: 
    480                     access_groups = [ priority_access_group ] 
    481                 else: 
    482                    access_roles = [ priority_access_role ] 
    483             elif priority_access_role: 
    484                  access_roles = [ priority_access_role ] 
    485             elif priority_access_group: 
    486                 access_groups = [ priority_access_group ] 
    487          
    488         return access_groups, access_roles 
    489     def add_group( self, group ): 
    490         return group.add_dataset( self ) 
    491     def add_role( self, role ): 
    492         return role.add_dataset( self ) 
    493      
    494     def has_group( self, group ): 
    495         return bool( GroupDatasetAssociation.get_by( group_id = group.id, dataset_id = self.id  )  ) 
    496     def has_role( self, role ): 
    497         return bool( RoleDatasetAssociation.get_by( role_id = role.id, dataset_id = self.id  )  ) 
    498  
    499     # FIXME: sqlalchemy will replace this 
    500     def _delete(self): 
    501         """Remove the file that corresponds to this data""" 
    502         try: 
    503             os.remove(self.data.file_name) 
    504         except OSError, e: 
    505             log.critical('%s delete error %s' % (self.__class__.__name__, e)) 
    506  
    507  
    508  
    509104class HistoryDatasetAssociation( object ): 
    510     states = Dataset.states 
    511     access_actions = Dataset.access_actions 
    512105    def __init__( self, id=None, hid=None, name=None, info=None, blurb=None, peek=None, extension=None,  
    513106                  dbkey=None, metadata=None, history=None, dataset=None, deleted=False, designation=None, 
    514                   parent_id=None, validation_errors=None, visible=True, create_dataset = False, access_groups = [], access_roles = [] ): 
     107                  parent_id=None, validation_errors=None, visible=True, create_dataset = False ): 
    515108        self.name = name or "Unnamed dataset" 
    516109        self.id = id 
     
    528121        self.history = history 
    529122        if not dataset and create_dataset: 
    530             dataset = Dataset( access_groups = access_groups, access_roles = access_roles
     123            dataset = Dataset(
    531124            dataset.flush() 
    532125        self.dataset = dataset 
     
    537130    def ext( self ): 
    538131        return self.extension 
     132     
     133    @property 
     134    def states( self ): 
     135        return self.dataset.states 
    539136     
    540137    def get_dataset_state( self ): 
     
    655252        return self.datatype.get_converter_types( self, datatypes_registry) 
    656253     
    657     def copy( self, copy_children = False, parent_id = None, target_user = None ): 
    658         if target_user is None: target_user = self.user 
     254    def copy( self, copy_children = False, parent_id = None ): 
    659255        des = HistoryDatasetAssociation( hid=self.hid, name=self.name, info=self.info, blurb=self.blurb, peek=self.peek, extension=self.extension, dbkey=self.dbkey, metadata=self._metadata, dataset = self.dataset, visible=self.visible, deleted=self.deleted, parent_id=parent_id ) 
    660256        des.flush() 
     
    678274                child.mark_deleted() 
    679275 
    680     def allow_action( self, user, action ): 
    681         return self.dataset.allow_action( user, action ) 
    682276 
    683277 
    684278class History( object ): 
    685     def __init__( self, id=None, name=None, user=None, default_roles = [], default_groups = [] ): 
     279    def __init__( self, id=None, name=None, user=None ): 
    686280        self.id = id 
    687281        self.name = name or "Unnamed history" 
     
    693287        self.datasets = [] 
    694288        self.galaxy_sessions = [] 
    695          
    696         if not default_roles: 
    697             if user: 
    698                 default_roles = user.default_roles 
    699         if not default_groups: 
    700             if user: 
    701                 default_groups = user.default_groups 
    702             else: 
    703                 default_groups = [ GalaxyGroup.get( GalaxyGroup.public_id ) ] 
    704          
    705          
    706         self.set_default_access( roles = default_roles, groups = default_groups ) 
    707289         
    708290    def _next_hid( self ): 
     
    744326        self.datasets.append( dataset ) 
    745327 
    746     def copy( self, target_user = None ): 
    747         if not target_user: 
    748             target_user = self.user 
    749         des = History( user = target_user ) 
     328    def copy(self): 
     329        des = History() 
    750330        des.flush() 
    751331        des.name = self.name 
     332        des.user_id = self.user_id 
    752333        for data in self.datasets: 
    753             new_data = data.copy( copy_children = True, target_user = target_user
     334            new_data = data.copy( copy_children = True
    754335            des.add_dataset( new_data ) 
    755336            new_data.flush() 
     
    757338        des.flush() 
    758339        return des 
    759      
    760     def set_default_access( self, groups = None, roles = None, dataset = False ): 
    761         if groups is not None: 
    762             for assoc in self.default_groups: #this is the association not the actual group 
    763                 assoc.delete() 
    764                 assoc.flush() 
    765             for group in groups: 
    766                 assoc = DefaultHistoryGroupAssociation( self, group ) 
    767                 assoc.flush() 
    768         if roles is not None: 
    769             for assoc in self.default_roles: #this is the association not the actual group 
    770                 assoc.delete() 
    771                 assoc.flush() 
    772             for role in roles: 
    773                 assoc = DefaultHistoryRoleAssociation( self, role ) 
    774                 assoc.flush() 
    775         if dataset: 
    776             for data in self.datasets: 
    777                 for hda in data.dataset.history_associations: 
    778                     if self.user and hda.history not in self.user.histories: 
    779                         break 
    780                 else: 
    781                     if groups is not None: 
    782                         for assoc in data.dataset.groups: #this is the association not the actual group 
    783                             assoc.delete() 
    784                             assoc.flush() 
    785                         for group in groups: 
    786                             group.add_dataset( data ) 
    787                     if roles is not None: 
    788                         for assoc in data.dataset.roles: #this is the association not the actual group 
    789                             assoc.delete() 
    790                             assoc.flush() 
    791                         for role in roles: 
    792                             role.add_dataset( data ) 
    793  
    794  
    795340 
    796341# class Query( object ): 
     
    802347#         self.history = history 
    803348#         self.datasets = [] 
     349 
     350class Dataset( object ): 
     351    states = Bunch( NEW = 'new', 
     352                    QUEUED = 'queued', 
     353                    RUNNING = 'running', 
     354                    OK = 'ok', 
     355                    EMPTY = 'empty', 
     356                    ERROR = 'error', 
     357                    DISCARDED = 'discarded' ) 
     358    file_path = "/tmp/" 
     359    engine = None 
     360    def __init__( self, id=None, state=None, external_filename=None, extra_files_path=None, file_size=None, purgable=True ): 
     361        self.id = id 
     362        self.state = state 
     363        self.deleted = False 
     364        self.purged = False 
     365        self.purgable = purgable 
     366        self.external_filename = external_filename 
     367        self._extra_files_path = extra_files_path 
     368        self.file_size = file_size 
     369         
     370    def get_file_name( self ): 
     371        if not self.external_filename: 
     372            assert self.id is not None, "ID must be set before filename used (commit the object)" 
     373            # First try filename directly under file_path 
     374            filename = os.path.join( self.file_path, "dataset_%d.dat" % self.id ) 
     375            # Only use that filename if it already exists (backward compatibility), 
     376            # otherwise construct hashed path 
     377            if not os.path.exists( filename ): 
     378                dir = os.path.join( self.file_path, *directory_hash_id( self.id ) ) 
     379                # Create directory if it does not exist 
     380                try: 
     381                    os.makedirs( dir ) 
     382                except OSError, e: 
     383                    # File Exists is okay, otherwise reraise 
     384                    if e.errno != errno.EEXIST: 
     385                        raise 
     386                # Return filename inside hashed directory 
     387                return os.path.abspath( os.path.join( dir, "dataset_%d.dat" % self.id ) ) 
     388        else: 
     389            filename = self.external_filename 
     390        # Make filename absolute 
     391        return os.path.abspath( filename ) 
     392             
     393    def set_file_name ( self, filename ): 
     394        if not filename: 
     395            self.external_filename = None 
     396        else: 
     397            self.external_filename = filename 
     398         
     399    file_name = property( get_file_name, set_file_name ) 
     400     
     401    @property 
     402    def extra_files_path( self ): 
     403        if self._extra_files_path:  
     404            path = self._extra_files_path 
     405        else: 
     406            path = os.path.join( self.file_path, "dataset_%d_files" % self.id ) 
     407            #only use path directly under self.file_path if it exists 
     408            if not os.path.exists( path ): 
     409                path = os.path.join( os.path.join( self.file_path, *directory_hash_id( self.id ) ), "dataset_%d_files" % self.id ) 
     410        # Make path absolute 
     411        return os.path.abspath( path ) 
     412     
     413    def get_size( self ): 
     414        """Returns the size of the data on disk""" 
     415        if self.file_size: 
     416            return self.file_size 
     417        else: 
     418            try: 
     419                return os.path.getsize( self.file_name ) 
     420            except OSError: 
     421                return 0 
     422    def set_size( self ): 
     423        """Returns the size of the data on disk""" 
     424        try: 
     425            self.file_size = os.path.getsize( self.file_name ) 
     426        except OSError: 
     427            self.file_size = 0 
     428    def has_data( self ): 
     429        """Detects whether there is any data""" 
     430        return self.get_size() > 0 
     431    def mark_deleted( self, include_children=True ): 
     432        self.deleted = True 
     433 
     434    # FIXME: sqlalchemy will replace this 
     435    def _delete(self): 
     436        """Remove the file that corresponds to this data""" 
     437        try: 
     438            os.remove(self.data.file_name) 
     439        except OSError, e: 
     440            log.critical('%s delete error %s' % (self.__class__.__name__, e)) 
    804441 
    805442class Old_Dataset( Dataset ): 
  • lib/galaxy/model/mapping.py

    r1454 r1459  
    113113    Column( "err_type", TrimmedString( 64 ) ), 
    114114    Column( "attributes", TEXT ) ) 
    115  
    116 GalaxyGroup.table = Table( "galaxy_group", metadata, 
    117     Column( "id", Integer, primary_key=True ), 
    118     Column( "create_time", DateTime, default=now ), 
    119     Column( "update_time", DateTime, default=now, onupdate=now ), 
    120     Column( "name", TEXT ), 
    121     Column( "priority", Integer ) ) 
    122  
    123 UserGroupAssociation.table = Table( "user_group_association", metadata,  
    124     Column( "id", Integer, primary_key=True ), 
    125     Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), 
    126     Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ), 
    127     Column( "create_time", DateTime, default=now ), 
    128     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    129  
    130 AccessRole.table = Table( "access_role", metadata, 
    131     Column( "id", Integer, primary_key=True ), 
    132     Column( "create_time", DateTime, default=now ), 
    133     Column( "update_time", DateTime, default=now, onupdate=now ), 
    134     Column( "name", TEXT ), 
    135     Column( "actions", JSONType(), default=[] ), 
    136     Column( "priority", Integer ) ) 
    137  
    138 UserRoleAssociation.table = Table( "user_role_association", metadata,  
    139     Column( "id", Integer, primary_key=True ), 
    140     Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), 
    141     Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    142     Column( "create_time", DateTime, default=now ), 
    143     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    144  
    145 GroupRoleAssociation.table = Table( "group_role_association", metadata,  
    146     Column( "id", Integer, primary_key=True ), 
    147     Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ), 
    148     Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    149     Column( "create_time", DateTime, default=now ), 
    150     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    151  
    152 GroupDatasetAssociation.table = Table( "group_dataset_association", metadata,  
    153     Column( "id", Integer, primary_key=True ), 
    154     Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ), 
    155     Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ), 
    156     Column( "create_time", DateTime, default=now ), 
    157     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    158  
    159 RoleDatasetAssociation.table = Table( "role_dataset_association", metadata,  
    160     Column( "id", Integer, primary_key=True ), 
    161     Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    162     Column( "dataset_id", Integer, ForeignKey( "dataset.id" ), index=True ), 
    163     Column( "create_time", DateTime, default=now ), 
    164     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    165  
    166 RoleRoleAssociation.table = Table( "role_role_association", metadata,  
    167     Column( "id", Integer, primary_key=True ), 
    168     Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    169     Column( "target_role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    170     Column( "create_time", DateTime, default=now ), 
    171     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    172  
    173 GroupRoleAccessAssociation.table = Table( "group_role_access_association", metadata,  
    174     Column( "id", Integer, primary_key=True ), 
    175     Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    176     Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ), 
    177     Column( "create_time", DateTime, default=now ), 
    178     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    179  
    180  
    181 DefaultUserRoleAssociation.table = Table( "default_user_role_association", metadata,  
    182     Column( "id", Integer, primary_key=True ), 
    183     Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    184     Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), 
    185     Column( "create_time", DateTime, default=now ), 
    186     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    187  
    188 DefaultUserGroupAssociation.table = Table( "default_user_group_association", metadata,  
    189     Column( "id", Integer, primary_key=True ), 
    190     Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ), 
    191     Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), 
    192     Column( "create_time", DateTime, default=now ), 
    193     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    194  
    195 DefaultHistoryRoleAssociation.table = Table( "default_history_role_association", metadata,  
    196     Column( "id", Integer, primary_key=True ), 
    197     Column( "role_id", Integer, ForeignKey( "access_role.id" ), index=True ), 
    198     Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ), 
    199     Column( "create_time", DateTime, default=now ), 
    200     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    201  
    202 DefaultHistoryGroupAssociation.table = Table( "default_history_group_association", metadata,  
    203     Column( "id", Integer, primary_key=True ), 
    204     Column( "group_id", Integer, ForeignKey( "galaxy_group.id" ), index=True ), 
    205     Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ), 
    206     Column( "create_time", DateTime, default=now ), 
    207     Column( "update_time", DateTime, default=now, onupdate=now ) ) 
    208115 
    209116Job.table = Table( "job", metadata, 
     
    386293                                                            collection_class=ordering_list( 'order_index' ) ) 
    387294                     ) ) 
    388  
    389 assign_mapper( context, GalaxyGroup, GalaxyGroup.table, 
    390     properties=dict( users=relation( UserGroupAssociation ), 
    391                      datasets=relation( GroupDatasetAssociation ) ) ) 
    392  
    393 assign_mapper( context, UserGroupAssociation, UserGroupAssociation.table, 
    394     properties=dict( user=relation( User, backref = "groups" ), 
    395                      group=relation( GalaxyGroup, backref = "users" ) ) ) 
    396  
    397 assign_mapper( context, UserRoleAssociation, UserRoleAssociation.table, 
    398     properties=dict( role=relation( AccessRole, backref = "users" ), 
    399                      user=relation( User, backref = "roles" ) ) ) 
    400  
    401 assign_mapper( context, GroupRoleAssociation, GroupRoleAssociation.table, 
    402     properties=dict( role=relation( AccessRole, backref = "groups" ), 
    403                      group=relation( GalaxyGroup, backref = "roles" ) ) ) 
    404  
    405 assign_mapper( context, AccessRole, AccessRole.table ) 
    406  
    407 assign_mapper( context, GroupDatasetAssociation, GroupDatasetAssociation.table, 
    408     properties=dict( dataset=relation( Dataset, backref = "groups" ), 
    409                      group=relation( GalaxyGroup, backref = "datasets" ) ) ) 
    410  
    411 assign_mapper( context, RoleDatasetAssociation, RoleDatasetAssociation.table, 
    412     properties=dict( dataset=relation( Dataset, backref = "roles" ), 
    413                      role=relation( AccessRole ) ) ) 
    414  
    415 assign_mapper( context, RoleRoleAssociation, RoleRoleAssociation.table, 
    416     properties=dict( role=relation( AccessRole, primaryjoin=( ( RoleRoleAssociation.table.c.role_id == AccessRole.table.c.id ) ) ), 
    417                      target_role=relation( AccessRole, primaryjoin=( RoleRoleAssociation.table.c.target_role_id == AccessRole.table.c.id ), backref="roles" ) ) ) 
    418  
    419 assign_mapper( context, GroupRoleAccessAssociation, GroupRoleAccessAssociation.table, 
    420     properties=dict( role=relation( AccessRole, backref="access_groups" ), 
    421                      group=relation( GalaxyGroup, backref="access_roles" ) ) ) 
    422  
    423 assign_mapper( context, DefaultUserRoleAssociation, DefaultUserRoleAssociation.table, 
    424     properties=dict( user=relation( User, backref = "default_roles" ), 
    425                      role=relation( AccessRole ) ) ) 
    426  
    427 assign_mapper( context, DefaultUserGroupAssociation, DefaultUserGroupAssociation.table, 
    428     properties=dict( user=relation( User, backref = "default_groups" ), 
    429                      group=relation( GalaxyGroup ) ) ) 
    430  
    431 assign_mapper( context, DefaultHistoryRoleAssociation, DefaultHistoryRoleAssociation.table, 
    432     properties=dict( history=relation( History, backref = "default_roles" ), 
    433                      role=relation( AccessRole ) ) ) 
    434  
    435 assign_mapper( context, DefaultHistoryGroupAssociation, DefaultHistoryGroupAssociation.table, 
    436     properties=dict( history=relation( History, backref = "default_groups" ), 
    437                      group=relation( GalaxyGroup ) ) ) 
    438295 
    439296assign_mapper( context, JobToInputDatasetAssociation, JobToInputDatasetAssociation.table, 
     
    550407    result.context = context 
    551408    result.create_tables = create_tables 
    552     #set up default table entries here, currently only exist for access controls 
    553     if result.AccessRole.count() == 0: 
    554         log.warning( "There were no access roles located, setting up default (public) access roles." ) 
    555         #create public group 
    556         public_group = result.GalaxyGroup( 'public' ) 
    557         public_group.flush() 
    558         #create public_all role 
    559         public_role = result.AccessRole( 'public', [ result.Dataset.access_actions.USE, result.Dataset.access_actions.VIEW, result.GalaxyGroup.access_actions.ADD_DATASET, result.GalaxyGroup.access_actions.REMOVE_DATASET ] ) 
    560         public_role.flush() 
    561         public_group.add_role( public_role ) 
    562          
    563         #store public group id 
    564         GalaxyGroup.public_id = public_group.id #we use the id instead of the object, because of alchemy sessions 
    565         #add all datasets to public group 
    566         for dataset in result.Dataset.select(): 
    567             public_group.add_dataset( dataset ) 
    568          
    569         #loop through all current users and associate with the public group  
    570         #and create and associate with user's own group 
    571         for user in result.User.select(): 
    572             public_group.add_user( user ) 
    573             private_group = user.create_private_group() 
    574             user.set_default_access( groups = [ public_group, private_group ], roles = [], history = True, dataset = True ) 
    575     else: 
    576         #retrieve from database and store public group id, assume first created group is public 
    577         GalaxyGroup.public_id = result.GalaxyGroup.select( order_by = asc( result.GalaxyGroup.table.c.create_time ) )[0].id #we use the id instead of the object, because of alchemy sessions 
    578     log.debug( "Public Group identified as id = %s." % ( GalaxyGroup.public_id ) ) 
    579409    return result 
    580410     
  • lib/galaxy/tools/__init__.py

    <
    r1454 r1459  
    10851085                else: visible = False 
    1086