Ejemplo n.º 1
0
 def purge_category(self, trans, **kwd):
     # This method should only be called for a Category that has previously been deleted.
     # Purging a deleted Category deletes all of the following from the database:
     # - RepoitoryCategoryAssociations where category_id == Category.id
     message = escape(kwd.get('message', ''))
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         purged_categories = ""
         message = "Purged %d categories: " % len(ids)
         for category_id in ids:
             category = suc.get_category(trans.app, category_id)
             if category.deleted:
                 # Delete RepositoryCategoryAssociations
                 for rca in category.repositories:
                     trans.sa_session.delete(rca)
                 trans.sa_session.flush()
                 purged_categories += " %s " % category.name
         message = "Purged %d categories: %s" % (count, escape(purged_categories))
     else:
         message = "No category ids received for purging."
     trans.response.send_redirect(web.url_for(controller='admin',
                                              action='manage_categories',
                                              message=util.sanitize_text(message),
                                              status='done'))
Ejemplo n.º 2
0
 def undelete_category(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category(trans.app, category_id)
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add(category)
                 trans.sa_session.flush()
                 # Update the Tool Shed's repository registry.
                 trans.app.repository_registry.add_category_entry(category)
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % (
             count, escape(undeleted_categories))
     else:
         message = "No category ids received for undeleting."
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Ejemplo n.º 3
0
 def undelete_category( self, trans, **kwd ):
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category( trans.app, category_id )
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add( category )
                 trans.sa_session.flush()
                 # Update the Tool Shed's repository registry.
                 trans.app.repository_registry.add_category_entry( category )
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % ( count, escape( undeleted_categories ) )
     else:
         message = "No category ids received for undeleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Ejemplo n.º 4
0
 def create_category(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     name = kwd.get('name', '').strip()
     description = kwd.get('description', '').strip()
     if kwd.get('create_category_button', False):
         if not name or not description:
             message = 'Enter a valid name and a description'
             status = 'error'
         elif suc.get_category_by_name(trans.app, name):
             message = 'A category with that name already exists'
             status = 'error'
         else:
             # Create the category
             category = trans.app.model.Category(name=name, description=description)
             trans.sa_session.add(category)
             trans.sa_session.flush()
             # Update the Tool Shed's repository registry.
             trans.app.repository_registry.add_category_entry(category)
             message = "Category '%s' has been created" % escape(category.name)
             status = 'done'
             trans.response.send_redirect(web.url_for(controller='admin',
                                                      action='manage_categories',
                                                      message=message,
                                                      status=status))
     return trans.fill_template('/webapps/tool_shed/category/create_category.mako',
                                name=name,
                                description=description,
                                message=message,
                                status=status)
Ejemplo n.º 5
0
 def create_category(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     name = kwd.get('name', '').strip()
     description = kwd.get('description', '').strip()
     if kwd.get('create_category_button', False):
         if not name or not description:
             message = 'Enter a valid name and a description'
             status = 'error'
         elif suc.get_category_by_name(trans.app, name):
             message = 'A category with that name already exists'
             status = 'error'
         else:
             # Create the category
             category = trans.app.model.Category(name=name,
                                                 description=description)
             trans.sa_session.add(category)
             trans.sa_session.flush()
             # Update the Tool Shed's repository registry.
             trans.app.repository_registry.add_category_entry(category)
             message = "Category '%s' has been created" % escape(
                 category.name)
             status = 'done'
             trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='manage_categories',
                             message=message,
                             status=status))
     return trans.fill_template(
         '/webapps/tool_shed/category/create_category.mako',
         name=name,
         description=description,
         message=message,
         status=status)
Ejemplo n.º 6
0
 def mark_category_deleted( self, trans, **kwd ):
     # TODO: We should probably eliminate the Category.deleted column since it really makes no
     # sense to mark a category as deleted (category names and descriptions can be changed instead).
     # If we do this, and the following 2 methods can be eliminated.
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         message = "Deleted %d categories: " % len( ids )
         for category_id in ids:
             category = suc.get_category( trans.app, category_id )
             category.deleted = True
             trans.sa_session.add( category )
             trans.sa_session.flush()
             # Update the Tool Shed's repository registry.
             trans.app.repository_registry.remove_category_entry( category )
             message += " %s " % escape( category.name )
     else:
         message = "No category ids received for deleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Ejemplo n.º 7
0
 def create_component( self, trans, **kwd ):
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     name = kwd.get( 'name', '' )
     description = kwd.get( 'description', '' )
     if kwd.get( 'create_component_button', False ):
         if not name or not description:
             message = 'Enter a valid name and a description'
             status = 'error'
         elif review_util.get_component_by_name( trans.app, name ):
             message = 'A component with that name already exists'
             status = 'error'
         else:
             component = trans.app.model.Component( name=name, description=description )
             trans.sa_session.add( component )
             trans.sa_session.flush()
             message = "Component '%s' has been created" % escape( component.name )
             status = 'done'
             trans.response.send_redirect( web.url_for( controller='repository_review',
                                                        action='manage_components',
                                                        message=message,
                                                        status=status ) )
     return trans.fill_template( '/webapps/tool_shed/repository_review/create_component.mako',
                                 name=name,
                                 description=description,
                                 message=message,
                                 status=status )
Ejemplo n.º 8
0
 def purge_category(self, trans, **kwd):
     # This method should only be called for a Category that has previously been deleted.
     # Purging a deleted Category deletes all of the following from the database:
     # - RepoitoryCategoryAssociations where category_id == Category.id
     message = escape(kwd.get('message', ''))
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         purged_categories = ""
         message = "Purged %d categories: " % len(ids)
         for category_id in ids:
             category = suc.get_category(trans.app, category_id)
             if category.deleted:
                 # Delete RepositoryCategoryAssociations
                 for rca in category.repositories:
                     trans.sa_session.delete(rca)
                 trans.sa_session.flush()
                 purged_categories += " %s " % category.name
         message = "Purged %d categories: %s" % (count,
                                                 escape(purged_categories))
     else:
         message = "No category ids received for purging."
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Ejemplo n.º 9
0
 def create_category(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     status = kwd.get("status", "done")
     name = kwd.get("name", "").strip()
     description = kwd.get("description", "").strip()
     if kwd.get("create_category_button", False):
         if not name or not description:
             message = "Enter a valid name and a description"
             status = "error"
         elif suc.get_category_by_name(trans.app, name):
             message = "A category with that name already exists"
             status = "error"
         else:
             # Create the category
             category = trans.app.model.Category(name=name, description=description)
             trans.sa_session.add(category)
             trans.sa_session.flush()
             # Update the Tool Shed's repository registry.
             trans.app.repository_registry.add_category_entry(category)
             message = "Category '%s' has been created" % escape(category.name)
             status = "done"
             trans.response.send_redirect(
                 web.url_for(controller="admin", action="manage_categories", message=message, status=status)
             )
     return trans.fill_template(
         "/webapps/tool_shed/category/create_category.mako",
         name=name,
         description=description,
         message=message,
         status=status,
     )
Ejemplo n.º 10
0
 def upload( self, trans, **kwd ):
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     commit_message = escape( kwd.get( 'commit_message', 'Uploaded'  ) )
     category_ids = util.listify( kwd.get( 'category_id', '' ) )
     categories = suc.get_categories( trans.app )
     repository_id = kwd.get( 'repository_id', '' )
     repository = suc.get_repository_in_tool_shed( trans.app, repository_id )
     repo_dir = repository.repo_path( trans.app )
     repo = hg_util.get_repo_for_repository( trans.app, repository=None, repo_path=repo_dir, create=False )
     uncompress_file = util.string_as_bool( kwd.get( 'uncompress_file', 'true' ) )
     remove_repo_files_not_in_tar = util.string_as_bool( kwd.get( 'remove_repo_files_not_in_tar', 'true' ) )
     uploaded_file = None
     upload_point = commit_util.get_upload_point( repository, **kwd )
     tip = repository.tip( trans.app )
     file_data = kwd.get( 'file_data', '' )
     url = kwd.get( 'url', '' )
     # Part of the upload process is sending email notification to those that have registered to
     # receive them.  One scenario occurs when the first change set is produced for the repository.
     # See the suc.handle_email_alerts() method for the definition of the scenarios.
     new_repo_alert = repository.is_new( trans.app )
     uploaded_directory = None
     if kwd.get( 'upload_button', False ):
         if file_data == '' and url == '':
             message = 'No files were entered on the upload form.'
             status = 'error'
             uploaded_file = None
         elif url and url.startswith( 'hg' ):
             # Use mercurial clone to fetch repository, contents will then be copied over.
             uploaded_directory = tempfile.mkdtemp()
             repo_url = 'http%s' % url[ len( 'hg' ): ]
             repo_url = repo_url.encode( 'ascii', 'replace' )
             try:
                 commands.clone( hg_util.get_configured_ui(), repo_url, uploaded_directory )
             except Exception, e:
                 message = 'Error uploading via mercurial clone: %s' % basic_util.to_html_string( str( e ) )
                 status = 'error'
                 basic_util.remove_dir( uploaded_directory )
                 uploaded_directory = None
         elif url:
             valid_url = True
             try:
                 stream = urllib.urlopen( url )
             except Exception, e:
                 valid_url = False
                 message = 'Error uploading file via http: %s' % str( e )
                 status = 'error'
                 uploaded_file = None
             if valid_url:
                 fd, uploaded_file_name = tempfile.mkstemp()
                 uploaded_file = open( uploaded_file_name, 'wb' )
                 while 1:
                     chunk = stream.read( util.CHUNK_SIZE )
                     if not chunk:
                         break
                     uploaded_file.write( chunk )
                 uploaded_file.flush()
                 uploaded_file_filename = url.split( '/' )[ -1 ]
                 isempty = os.path.getsize( os.path.abspath( uploaded_file_name ) ) == 0
Ejemplo n.º 11
0
def handle_role_associations(app, role, repository, **kwd):
    sa_session = app.model.context.current
    message = escape(kwd.get('message', ''))
    status = kwd.get('status', 'done')
    repository_owner = repository.user
    if kwd.get('manage_role_associations_button', False):
        in_users_list = util.listify(kwd.get('in_users', []))
        in_users = [
            sa_session.query(app.model.User).get(x) for x in in_users_list
        ]
        # Make sure the repository owner is always associated with the repostory's admin role.
        owner_associated = False
        for user in in_users:
            if user.id == repository_owner.id:
                owner_associated = True
                break
        if not owner_associated:
            in_users.append(repository_owner)
            message += "The repository owner must always be associated with the repository's administrator role.  "
            status = 'error'
        in_groups_list = util.listify(kwd.get('in_groups', []))
        in_groups = [
            sa_session.query(app.model.Group).get(x) for x in in_groups_list
        ]
        in_repositories = [repository]
        app.security_agent.set_entity_role_associations(
            roles=[role],
            users=in_users,
            groups=in_groups,
            repositories=in_repositories)
        sa_session.refresh(role)
        message += "Role <b>%s</b> has been associated with %d users, %d groups and %d repositories.  " % \
            ( escape( str( role.name ) ), len( in_users ), len( in_groups ), len( in_repositories ) )
    in_users = []
    out_users = []
    in_groups = []
    out_groups = []
    for user in sa_session.query( app.model.User ) \
                          .filter( app.model.User.table.c.deleted == false() ) \
                          .order_by( app.model.User.table.c.email ):
        if user in [x.user for x in role.users]:
            in_users.append((user.id, user.email))
        else:
            out_users.append((user.id, user.email))
    for group in sa_session.query( app.model.Group ) \
                           .filter( app.model.Group.table.c.deleted == false() ) \
                           .order_by( app.model.Group.table.c.name ):
        if group in [x.group for x in role.groups]:
            in_groups.append((group.id, group.name))
        else:
            out_groups.append((group.id, group.name))
    associations_dict = dict(in_users=in_users,
                             out_users=out_users,
                             in_groups=in_groups,
                             out_groups=out_groups,
                             message=message,
                             status=status)
    return associations_dict
Ejemplo n.º 12
0
 def upload( self, trans, **kwd ):
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     commit_message = escape( kwd.get( 'commit_message', 'Uploaded'  ) )
     repository_id = kwd.get( 'repository_id', '' )
     repository = suc.get_repository_in_tool_shed( trans.app, repository_id )
     repo_dir = repository.repo_path( trans.app )
     repo = hg_util.get_repo_for_repository( trans.app, repository=None, repo_path=repo_dir, create=False )
     uncompress_file = util.string_as_bool( kwd.get( 'uncompress_file', 'true' ) )
     remove_repo_files_not_in_tar = util.string_as_bool( kwd.get( 'remove_repo_files_not_in_tar', 'true' ) )
     uploaded_file = None
     upload_point = commit_util.get_upload_point( repository, **kwd )
     tip = repository.tip( trans.app )
     file_data = kwd.get( 'file_data', '' )
     url = kwd.get( 'url', '' )
     # Part of the upload process is sending email notification to those that have registered to
     # receive them.  One scenario occurs when the first change set is produced for the repository.
     # See the suc.handle_email_alerts() method for the definition of the scenarios.
     new_repo_alert = repository.is_new( trans.app )
     uploaded_directory = None
     if kwd.get( 'upload_button', False ):
         if file_data == '' and url == '':
             message = 'No files were entered on the upload form.'
             status = 'error'
             uploaded_file = None
         elif url and url.startswith( 'hg' ):
             # Use mercurial clone to fetch repository, contents will then be copied over.
             uploaded_directory = tempfile.mkdtemp()
             repo_url = 'http%s' % url[ len( 'hg' ): ]
             repo_url = repo_url.encode( 'ascii', 'replace' )
             try:
                 commands.clone( hg_util.get_configured_ui(), repo_url, uploaded_directory )
             except Exception, e:
                 message = 'Error uploading via mercurial clone: %s' % basic_util.to_html_string( str( e ) )
                 status = 'error'
                 basic_util.remove_dir( uploaded_directory )
                 uploaded_directory = None
         elif url:
             valid_url = True
             try:
                 stream = urllib.urlopen( url )
             except Exception, e:
                 valid_url = False
                 message = 'Error uploading file via http: %s' % str( e )
                 status = 'error'
                 uploaded_file = None
             if valid_url:
                 fd, uploaded_file_name = tempfile.mkstemp()
                 uploaded_file = open( uploaded_file_name, 'wb' )
                 while 1:
                     chunk = stream.read( util.CHUNK_SIZE )
                     if not chunk:
                         break
                     uploaded_file.write( chunk )
                 uploaded_file.flush()
                 uploaded_file_filename = url.split( '/' )[ -1 ]
                 isempty = os.path.getsize( os.path.abspath( uploaded_file_name ) ) == 0
Ejemplo n.º 13
0
 def edit_category(self, trans, **kwd):
     '''Handle requests to edit TS category name or description'''
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     id = kwd.get('id', None)
     if not id:
         message = "No category ids received for editing"
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='manage_categories',
                         message=message,
                         status='error'))
     category = suc.get_category(trans.app, id)
     original_category_name = str(category.name)
     original_category_description = str(category.description)
     if kwd.get('edit_category_button', False):
         flush_needed = False
         new_name = kwd.get('name', '').strip()
         new_description = kwd.get('description', '').strip()
         if original_category_name != new_name:
             if not new_name:
                 message = 'Enter a valid name'
                 status = 'error'
             elif original_category_name != new_name and suc.get_category_by_name(
                     trans.app, new_name):
                 message = 'A category with that name already exists'
                 status = 'error'
             else:
                 category.name = new_name
                 flush_needed = True
         if original_category_description != new_description:
             category.description = new_description
             if not flush_needed:
                 flush_needed = True
         if flush_needed:
             trans.sa_session.add(category)
             trans.sa_session.flush()
             if original_category_name != new_name:
                 # Update the Tool Shed's repository registry.
                 trans.app.repository_registry.edit_category_entry(
                     original_category_name, new_name)
             message = "The information has been saved for category '%s'" % escape(
                 category.name)
             status = 'done'
             return trans.response.send_redirect(
                 web.url_for(controller='admin',
                             action='manage_categories',
                             message=message,
                             status=status))
     return trans.fill_template(
         '/webapps/tool_shed/category/edit_category.mako',
         category=category,
         message=message,
         status=status)
Ejemplo n.º 14
0
def handle_role_associations( app, role, repository, **kwd ):
    sa_session = app.model.context.current
    message = escape( kwd.get( 'message', '' ) )
    status = kwd.get( 'status', 'done' )
    repository_owner = repository.user
    if kwd.get( 'manage_role_associations_button', False ):
        in_users_list = util.listify( kwd.get( 'in_users', [] ) )
        in_users = [ sa_session.query( app.model.User ).get( x ) for x in in_users_list ]
        # Make sure the repository owner is always associated with the repostory's admin role.
        owner_associated = False
        for user in in_users:
            if user.id == repository_owner.id:
                owner_associated = True
                break
        if not owner_associated:
            in_users.append( repository_owner )
            message += "The repository owner must always be associated with the repository's administrator role.  "
            status = 'error'
        in_groups_list = util.listify( kwd.get( 'in_groups', [] ) )
        in_groups = [ sa_session.query( app.model.Group ).get( x ) for x in in_groups_list ]
        in_repositories = [ repository ]
        app.security_agent.set_entity_role_associations( roles=[ role ],
                                                               users=in_users,
                                                               groups=in_groups,
                                                               repositories=in_repositories  )
        sa_session.refresh( role )
        message += "Role <b>%s</b> has been associated with %d users, %d groups and %d repositories.  " % \
            ( escape( str( role.name ) ), len( in_users ), len( in_groups ), len( in_repositories ) )
    in_users = []
    out_users = []
    in_groups = []
    out_groups = []
    for user in sa_session.query( app.model.User ) \
                          .filter( app.model.User.table.c.deleted==False ) \
                          .order_by( app.model.User.table.c.email ):
        if user in [ x.user for x in role.users ]:
            in_users.append( ( user.id, user.email ) )
        else:
            out_users.append( ( user.id, user.email ) )
    for group in sa_session.query( app.model.Group ) \
                           .filter( app.model.Group.table.c.deleted==False ) \
                           .order_by( app.model.Group.table.c.name ):
        if group in [ x.group for x in role.groups ]:
            in_groups.append( ( group.id, group.name ) )
        else:
            out_groups.append( ( group.id, group.name ) )
    associations_dict = dict( in_users=in_users,
                              out_users=out_users,
                              in_groups=in_groups,
                              out_groups=out_groups,
                              message=message,
                              status=status )
    return associations_dict
Ejemplo n.º 15
0
 def edit_category(self, trans, **kwd):
     '''Handle requests to edit TS category name or description'''
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     id = kwd.get('id', None)
     if not id:
         message = "No category ids received for editing"
         trans.response.send_redirect(web.url_for(controller='admin',
                                                  action='manage_categories',
                                                  message=message,
                                                  status='error'))
     category = suc.get_category(trans.app, id)
     original_category_name = str(category.name)
     original_category_description = str(category.description)
     if kwd.get('edit_category_button', False):
         flush_needed = False
         new_name = kwd.get('name', '').strip()
         new_description = kwd.get('description', '').strip()
         if original_category_name != new_name:
             if not new_name:
                 message = 'Enter a valid name'
                 status = 'error'
             elif original_category_name != new_name and suc.get_category_by_name(trans.app, new_name):
                 message = 'A category with that name already exists'
                 status = 'error'
             else:
                 category.name = new_name
                 flush_needed = True
         if original_category_description != new_description:
             category.description = new_description
             if not flush_needed:
                 flush_needed = True
         if flush_needed:
             trans.sa_session.add(category)
             trans.sa_session.flush()
             if original_category_name != new_name:
                 # Update the Tool Shed's repository registry.
                 trans.app.repository_registry.edit_category_entry(original_category_name, new_name)
             message = "The information has been saved for category '%s'" % escape(category.name)
             status = 'done'
             return trans.response.send_redirect(web.url_for(controller='admin',
                                                             action='manage_categories',
                                                             message=message,
                                                             status=status))
     return trans.fill_template('/webapps/tool_shed/category/edit_category.mako',
                                category=category,
                                message=message,
                                status=status)
Ejemplo n.º 16
0
def check_for_updates( app, model, repository_id=None ):
    message = ''
    status = 'ok'
    if repository_id is None:
        success_count = 0
        repository_names_not_updated = []
        updated_count = 0
        for repository in model.context.query( model.ToolShedRepository ) \
                                       .filter( model.ToolShedRepository.table.c.deleted == false() ):
            ok, updated = \
                check_or_update_tool_shed_status_for_installed_repository( app, repository )
            if ok:
                success_count += 1
            else:
                repository_names_not_updated.append( '<b>%s</b>' % escape( str( repository.name ) ) )
            if updated:
                updated_count += 1
        message = "Checked the status in the tool shed for %d repositories.  " % success_count
        message += "Updated the tool shed status for %d repositories.  " % updated_count
        if repository_names_not_updated:
            message += "Unable to retrieve status from the tool shed for the following repositories:\n"
            message += ", ".join( repository_names_not_updated )
    else:
        repository = suc.get_tool_shed_repository_by_id( app, repository_id )
        ok, updated = \
            check_or_update_tool_shed_status_for_installed_repository( app, repository )
        if ok:
            if updated:
                message = "The tool shed status for repository <b>%s</b> has been updated." % escape( str( repository.name ) )
            else:
                message = "The status has not changed in the tool shed for repository <b>%s</b>." % escape( str( repository.name ) )
        else:
            message = "Unable to retrieve status from the tool shed for repository <b>%s</b>." % escape( str( repository.name ) )
            status = 'error'
    return message, status
Ejemplo n.º 17
0
 def regenerate_statistics(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     status = kwd.get("status", "done")
     if "regenerate_statistics_button" in kwd:
         trans.app.shed_counter.generate_statistics()
         message = "Successfully regenerated statistics"
     return trans.fill_template("/webapps/tool_shed/admin/statistics.mako", message=message, status=status)
Ejemplo n.º 18
0
 def delete_repository_metadata(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     status = kwd.get("status", "done")
     id = kwd.get("id", None)
     if id:
         ids = util.listify(id)
         count = 0
         for repository_metadata_id in ids:
             repository_metadata = metadata_util.get_repository_metadata_by_id(trans.app, repository_metadata_id)
             trans.sa_session.delete(repository_metadata)
             trans.sa_session.flush()
             count += 1
         if count:
             message = "Deleted %d repository metadata %s" % (count, inflector.cond_plural(len(ids), "record"))
     else:
         message = "No repository metadata ids received for deleting."
         status = "error"
     trans.response.send_redirect(
         web.url_for(
             controller="admin",
             action="browse_repository_metadata",
             message=util.sanitize_text(message),
             status=status,
         )
     )
Ejemplo n.º 19
0
 def edit_component( self, trans, **kwd ):
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if not id:
         message = "No component ids received for editing"
         trans.response.send_redirect( web.url_for( controller='admin',
                                                    action='manage_categories',
                                                    message=message,
                                                    status='error' ) )
     component = review_util.get_component( trans.app, id )
     if kwd.get( 'edit_component_button', False ):
         new_description = kwd.get( 'description', '' ).strip()
         if component.description != new_description:
             component.description = new_description
             trans.sa_session.add( component )
             trans.sa_session.flush()
             message = "The information has been saved for the component named <b>%s</b>" % escape( component.name )
             status = 'done'
             return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                               action='manage_components',
                                                               message=message,
                                                               status=status ) )
     return trans.fill_template( '/webapps/tool_shed/repository_review/edit_component.mako',
                                 component=component,
                                 message=message,
                                 status=status )
Ejemplo n.º 20
0
    def repository_reviews_by_user(self, trans, **kwd):
        message = escape(kwd.get('message', ''))
        status = kwd.get('status', 'done')

        if 'operation' in kwd:
            operation = kwd['operation'].lower()
            # The value of the received id is the encoded review id.
            review = review_util.get_review(trans.app, kwd['id'])
            repository = review.repository
            kwd['id'] = trans.security.encode_id(repository.id)
            if operation == "inspect repository revisions":
                return trans.response.send_redirect(
                    web.url_for(controller='repository_review',
                                action='manage_repository_reviews',
                                **kwd))
            if operation == "view_or_manage_repository":
                kwd['changeset_revision'] = review.changeset_revision
                return trans.response.send_redirect(
                    web.url_for(controller='repository_review',
                                action='view_or_manage_repository',
                                **kwd))
        # The user may not be the current user.  The value of the received id is the encoded user id.
        user = suc.get_user(trans.app, kwd['id'])
        self.repository_reviews_by_user_grid.title = "All repository revision reviews for user '%s'" % user.username
        return self.repository_reviews_by_user_grid(trans, **kwd)
Ejemplo n.º 21
0
 def review_tool_migration_stages( self, trans, **kwd ):
     message = escape( galaxy.util.restore_text( kwd.get( 'message', '' ) ) )
     status = galaxy.util.restore_text( kwd.get( 'status', 'done' ) )
     migration_stages_dict = odict()
     migration_modules = []
     migration_scripts_dir = os.path.abspath( os.path.join( trans.app.config.root, 'lib', 'tool_shed', 'galaxy_install', 'migrate', 'versions' ) )
     migration_scripts_dir_contents = os.listdir( migration_scripts_dir )
     for item in migration_scripts_dir_contents:
         if os.path.isfile( os.path.join( migration_scripts_dir, item ) ) and item.endswith( '.py' ):
             module = item.replace( '.py', '' )
             migration_modules.append( module )
     if migration_modules:
         migration_modules.sort()
         # Remove the 0001_tools.py script since it is the seed.
         migration_modules = migration_modules[ 1: ]
         # Reverse the list so viewing will be newest to oldest.
         migration_modules.reverse()
     for migration_module in migration_modules:
         migration_stage = int( migration_module.replace( '_tools', '' ) )
         repo_name_dependency_tups = self.check_for_tool_dependencies( trans, migration_stage )
         open_file_obj, file_name, description = imp.find_module( migration_module, [ migration_scripts_dir ] )
         imported_module = imp.load_module( 'upgrade', open_file_obj, file_name, description )
         migration_info = imported_module.__doc__
         open_file_obj.close()
         migration_stages_dict[ migration_stage ] = ( migration_info, repo_name_dependency_tups )
     return trans.fill_template( 'admin/review_tool_migration_stages.mako',
                                 migration_stages_dict=migration_stages_dict,
                                 message=message,
                                 status=status )
Ejemplo n.º 22
0
 def manage_repository_reviews(self, trans, mine=False, **kwd):
     # The value of the received id is the encoded repository id.
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     repository_id = kwd.get('id', None)
     if repository_id:
         repository = suc.get_repository_in_tool_shed(
             trans.app, repository_id)
         repo = hg_util.get_repo_for_repository(trans.app,
                                                repository=repository)
         metadata_revision_hashes = [
             metadata_revision.changeset_revision
             for metadata_revision in repository.metadata_revisions
         ]
         reviewed_revision_hashes = [
             review.changeset_revision for review in repository.reviews
         ]
         reviews_dict = OrderedDict()
         for changeset in hg_util.get_reversed_changelog_changesets(repo):
             changeset_revision = str(repo[changeset])
             if changeset_revision in metadata_revision_hashes or changeset_revision in reviewed_revision_hashes:
                 rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision(
                     repo, changeset_revision)
                 if changeset_revision in reviewed_revision_hashes:
                     # Find the review for this changeset_revision
                     repository_reviews = \
                         review_util.get_reviews_by_repository_id_changeset_revision(trans.app,
                                                                                     repository_id,
                                                                                     changeset_revision)
                     # Determine if the current user can add a review to this revision.
                     can_add_review = trans.user not in [
                         repository_review.user
                         for repository_review in repository_reviews
                     ]
                     repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(
                         trans.app, repository_id, changeset_revision)
                     if repository_metadata:
                         repository_metadata_reviews = util.listify(
                             repository_metadata.reviews)
                     else:
                         repository_metadata_reviews = []
                 else:
                     repository_reviews = []
                     repository_metadata_reviews = []
                     can_add_review = True
                 installable = changeset_revision in metadata_revision_hashes
                 revision_dict = dict(
                     changeset_revision_label=changeset_revision_label,
                     repository_reviews=repository_reviews,
                     repository_metadata_reviews=repository_metadata_reviews,
                     installable=installable,
                     can_add_review=can_add_review)
                 reviews_dict[changeset_revision] = revision_dict
     return trans.fill_template(
         '/webapps/tool_shed/repository_review/reviews_of_repository.mako',
         repository=repository,
         reviews_dict=reviews_dict,
         mine=mine,
         message=message,
         status=status)
Ejemplo n.º 23
0
 def manage_repository_reviews_of_revision(self, trans, **kwd):
     # The value of the received id is the encoded repository id.
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     repository_id = kwd.get('id', None)
     changeset_revision = kwd.get('changeset_revision', None)
     repository = suc.get_repository_in_tool_shed(trans.app, repository_id)
     repo = hg_util.get_repo_for_repository(trans.app,
                                            repository=repository,
                                            repo_path=None,
                                            create=False)
     installable = changeset_revision in [
         metadata_revision.changeset_revision
         for metadata_revision in repository.metadata_revisions
     ]
     rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision(
         repo, changeset_revision)
     reviews = review_util.get_reviews_by_repository_id_changeset_revision(
         trans.app, repository_id, changeset_revision)
     return trans.fill_template(
         '/webapps/tool_shed/repository_review/reviews_of_changeset_revision.mako',
         repository=repository,
         changeset_revision=changeset_revision,
         changeset_revision_label=changeset_revision_label,
         reviews=reviews,
         installable=installable,
         message=message,
         status=status)
Ejemplo n.º 24
0
def create_repository(
    app,
    name,
    type,
    description,
    long_description,
    user_id,
    category_ids=[],
    remote_repository_url=None,
    homepage_url=None,
):
    """Create a new ToolShed repository"""
    sa_session = app.model.context.current
    # Add the repository record to the database.
    repository = app.model.Repository(
        name=name,
        type=type,
        remote_repository_url=remote_repository_url,
        homepage_url=homepage_url,
        description=description,
        long_description=long_description,
        user_id=user_id,
    )
    # Flush to get the id.
    sa_session.add(repository)
    sa_session.flush()
    # Create an admin role for the repository.
    repository_admin_role = create_repository_admin_role(app, repository)
    # Determine the repository's repo_path on disk.
    dir = os.path.join(app.config.file_path, *directory_hash_id(repository.id))
    # Create directory if it does not exist.
    if not os.path.exists(dir):
        os.makedirs(dir)
    # Define repo name inside hashed directory.
    repository_path = os.path.join(dir, "repo_%d" % repository.id)
    # Create local repository directory.
    if not os.path.exists(repository_path):
        os.makedirs(repository_path)
    # Create the local repository.
    repo = hg_util.get_repo_for_repository(app, repository=None, repo_path=repository_path, create=True)
    # Add an entry in the hgweb.config file for the local repository.
    lhs = "repos/%s/%s" % (repository.user.username, repository.name)
    app.hgweb_config_manager.add_entry(lhs, repository_path)
    # Create a .hg/hgrc file for the local repository.
    hg_util.create_hgrc_file(app, repository)
    flush_needed = False
    if category_ids:
        # Create category associations
        for category_id in category_ids:
            category = sa_session.query(app.model.Category).get(app.security.decode_id(category_id))
            rca = app.model.RepositoryCategoryAssociation(repository, category)
            sa_session.add(rca)
            flush_needed = True
    if flush_needed:
        sa_session.flush()
    # Update the repository registry.
    app.repository_registry.add_entry(repository)
    message = "Repository <b>%s</b> has been created." % escape(str(repository.name))
    return repository, message
Ejemplo n.º 25
0
 def delete_repository(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     status = kwd.get("status", "done")
     id = kwd.get("id", None)
     if id:
         # Deleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify(id)
         count = 0
         deleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed(trans.app, repository_id)
             if repository:
                 if not repository.deleted:
                     # Mark all installable repository_metadata records as not installable.
                     for repository_metadata in repository.downloadable_revisions:
                         repository_metadata.downloadable = False
                         trans.sa_session.add(repository_metadata)
                     # Mark the repository admin role as deleted.
                     repository_admin_role = repository.admin_role
                     if repository_admin_role is not None:
                         repository_admin_role.deleted = True
                         trans.sa_session.add(repository_admin_role)
                     repository.deleted = True
                     trans.sa_session.add(repository)
                     trans.sa_session.flush()
                     # Update the repository registry.
                     trans.app.repository_registry.remove_entry(repository)
                     count += 1
                     deleted_repositories += " %s " % repository.name
         if count:
             message = "Deleted %d %s: %s" % (
                 count,
                 inflector.cond_plural(len(ids), "repository"),
                 escape(deleted_repositories),
             )
         else:
             message = "All selected repositories were already marked deleted."
     else:
         message = "No repository ids received for deleting."
         status = "error"
     trans.response.send_redirect(
         web.url_for(
             controller="admin", action="browse_repositories", message=util.sanitize_text(message), status=status
         )
     )
Ejemplo n.º 26
0
 def regenerate_statistics(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     if 'regenerate_statistics_button' in kwd:
         trans.app.shed_counter.generate_statistics()
         message = "Successfully regenerated statistics"
     return trans.fill_template('/webapps/tool_shed/admin/statistics.mako',
                                message=message,
                                status=status)
Ejemplo n.º 27
0
 def regenerate_statistics(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     if 'regenerate_statistics_button' in kwd:
         trans.app.shed_counter.generate_statistics()
         message = "Successfully regenerated statistics"
     return trans.fill_template('/webapps/tool_shed/admin/statistics.mako',
                                message=message,
                                status=status)
Ejemplo n.º 28
0
 def edit_category(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     status = kwd.get("status", "done")
     id = kwd.get("id", None)
     if not id:
         message = "No category ids received for editing"
         trans.response.send_redirect(
             web.url_for(controller="admin", action="manage_categories", message=message, status="error")
         )
     category = suc.get_category(trans.app, id)
     original_category_name = str(category.name)
     original_category_description = str(category.description)
     if kwd.get("edit_category_button", False):
         flush_needed = False
         new_name = kwd.get("name", "").strip()
         new_description = kwd.get("description", "").strip()
         if original_category_name != new_name:
             if not new_name:
                 message = "Enter a valid name"
                 status = "error"
             elif original_category_name != new_name and suc.get_category_by_name(trans.app, new_name):
                 message = "A category with that name already exists"
                 status = "error"
             else:
                 category.name = new_name
                 flush_needed = True
             if original_category_description != new_description:
                 category.description = new_description
                 if not flush_needed:
                     flush_needed = True
             if flush_needed:
                 trans.sa_session.add(category)
                 trans.sa_session.flush()
                 if original_category_name != new_name:
                     # Update the Tool Shed's repository registry.
                     trans.app.repository_registry.edit_category_entry(original_category_name, new_name)
                 message = "The information has been saved for category '%s'" % escape(category.name)
                 status = "done"
                 return trans.response.send_redirect(
                     web.url_for(controller="admin", action="manage_categories", message=message, status=status)
                 )
     return trans.fill_template(
         "/webapps/tool_shed/category/edit_category.mako", category=category, message=message, status=status
     )
Ejemplo n.º 29
0
 def delete_repository(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         # Deleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify(id)
         count = 0
         deleted_repositories = ""
         for repository_id in ids:
             repository = repository_util.get_repository_in_tool_shed(
                 trans.app, repository_id)
             if repository:
                 if not repository.deleted:
                     # Mark all installable repository_metadata records as not installable.
                     for repository_metadata in repository.downloadable_revisions:
                         repository_metadata.downloadable = False
                         trans.sa_session.add(repository_metadata)
                     # Mark the repository admin role as deleted.
                     repository_admin_role = repository.admin_role
                     if repository_admin_role is not None:
                         repository_admin_role.deleted = True
                         trans.sa_session.add(repository_admin_role)
                     repository.deleted = True
                     trans.sa_session.add(repository)
                     trans.sa_session.flush()
                     # Update the repository registry.
                     trans.app.repository_registry.remove_entry(repository)
                     count += 1
                     deleted_repositories += " %s " % repository.name
         if count:
             message = "Deleted %d %s: %s" % (
                 count, inflector.cond_plural(
                     len(ids), "repository"), escape(deleted_repositories))
         else:
             message = "All selected repositories were already marked deleted."
     else:
         message = "No repository ids received for deleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='browse_repositories',
                     message=util.sanitize_text(message),
                     status=status))
Ejemplo n.º 30
0
def create_repository(app,
                      name,
                      type,
                      description,
                      long_description,
                      user_id,
                      category_ids=[]):
    sa_session = app.model.context.current
    # Add the repository record to the database.
    repository = app.model.Repository(name=name,
                                      type=type,
                                      description=description,
                                      long_description=long_description,
                                      user_id=user_id)
    # Flush to get the id.
    sa_session.add(repository)
    sa_session.flush()
    # Create an admin role for the repository.
    repository_admin_role = create_repository_admin_role(app, repository)
    # Determine the repository's repo_path on disk.
    dir = os.path.join(app.config.file_path, *directory_hash_id(repository.id))
    # Create directory if it does not exist.
    if not os.path.exists(dir):
        os.makedirs(dir)
    # Define repo name inside hashed directory.
    repository_path = os.path.join(dir, "repo_%d" % repository.id)
    # Create local repository directory.
    if not os.path.exists(repository_path):
        os.makedirs(repository_path)
    # Create the local repository.
    repo = hg_util.get_repo_for_repository(app,
                                           repository=None,
                                           repo_path=repository_path,
                                           create=True)
    # Add an entry in the hgweb.config file for the local repository.
    lhs = "repos/%s/%s" % (repository.user.username, repository.name)
    app.hgweb_config_manager.add_entry(lhs, repository_path)
    # Create a .hg/hgrc file for the local repository.
    hg_util.create_hgrc_file(app, repository)
    flush_needed = False
    if category_ids:
        # Create category associations
        for category_id in category_ids:
            category = sa_session.query( app.model.Category ) \
                                 .get( app.security.decode_id( category_id ) )
            rca = app.model.RepositoryCategoryAssociation(repository, category)
            sa_session.add(rca)
            flush_needed = True
    if flush_needed:
        sa_session.flush()
    # Update the repository registry.
    app.repository_registry.add_entry(repository)
    message = "Repository <b>%s</b> has been created." % escape(
        str(repository.name))
    return repository, message
Ejemplo n.º 31
0
 def manage_repositories_reviewed_by_me( self, trans, **kwd ):
     # The value of the received id is the encoded repository id.
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     if 'operation' in kwd:
         kwd[ 'mine' ] = True
         return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                           action='manage_repositories_with_reviews',
                                                           **kwd ) )
     self.repositories_reviewed_by_me_grid.title = 'Repositories reviewed by me'
     return self.repositories_reviewed_by_me_grid( trans, **kwd )
Ejemplo n.º 32
0
 def approve_repository_review( self, trans, **kwd ):
     # The value of the received id is the encoded review id.
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     encoded_review_id = kwd[ 'id' ]
     review = review_util.get_review( trans.app, encoded_review_id )
     if kwd.get( 'approve_repository_review_button', False ):
         approved_select_field_name = '%s%sapproved' % ( encoded_review_id, STRSEP )
         approved_select_field_value = str( kwd[ approved_select_field_name ] )
         review.approved = approved_select_field_value
         trans.sa_session.add( review )
         trans.sa_session.flush()
         message = 'Approved value <b>%s</b> saved for this revision.' % escape( approved_select_field_value )
     repository_id = trans.security.encode_id( review.repository_id )
     changeset_revision = review.changeset_revision
     return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                       action='manage_repository_reviews_of_revision',
                                                       id=repository_id,
                                                       changeset_revision=changeset_revision,
                                                       message=message,
                                                       status=status ) )
Ejemplo n.º 33
0
 def manage_repositories_reviewed_by_me(self, trans, **kwd):
     # The value of the received id is the encoded repository id.
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     if 'operation' in kwd:
         kwd['mine'] = True
         return trans.response.send_redirect(
             web.url_for(controller='repository_review',
                         action='manage_repositories_with_reviews',
                         **kwd))
     self.repositories_reviewed_by_me_grid.title = 'Repositories reviewed by me'
     return self.repositories_reviewed_by_me_grid(trans, **kwd)
Ejemplo n.º 34
0
 def browse_review( self, trans, **kwd ):
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     review = review_util.get_review( trans.app, kwd[ 'id' ] )
     repository = review.repository
     repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False )
     rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, review.changeset_revision )
     return trans.fill_template( '/webapps/tool_shed/repository_review/browse_review.mako',
                                 repository=repository,
                                 changeset_revision_label=changeset_revision_label,
                                 review=review,
                                 message=message,
                                 status=status )
 def undelete_repository(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify(id)
         count = 0
         undeleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed(
                 trans.app, repository_id)
             if repository:
                 if repository.deleted:
                     # Inspect all repository_metadata records to determine those that are installable, and mark
                     # them accordingly.
                     for repository_metadata in repository.metadata_revisions:
                         metadata = repository_metadata.metadata
                         if metadata:
                             if metadata_util.is_downloadable(metadata):
                                 repository_metadata.downloadable = True
                                 trans.sa_session.add(repository_metadata)
                     # Mark the repository admin role as not deleted.
                     repository_admin_role = repository.admin_role
                     if repository_admin_role is not None:
                         repository_admin_role.deleted = False
                         trans.sa_session.add(repository_admin_role)
                     repository.deleted = False
                     trans.sa_session.add(repository)
                     trans.sa_session.flush()
                     if not repository.deprecated:
                         # Update the repository registry.
                         trans.app.repository_registry.add_entry(repository)
                     count += 1
                     undeleted_repositories += " %s" % repository.name
         if count:
             message = "Undeleted %d %s: %s" % (
                 count, inflector.cond_plural(
                     count, "repository"), undeleted_repositories)
         else:
             message = "No selected repositories were marked deleted, so they could not be undeleted."
     else:
         message = "No repository ids received for undeleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='browse_repositories',
                     message=util.sanitize_text(message),
                     status='done'))
Ejemplo n.º 36
0
 def reviewed_repositories_i_own( self, trans, **kwd ):
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     # The value of the received id is the encoded repository id.
     if 'operation' in kwd:
         operation = kwd['operation'].lower()
         if operation == "inspect repository revisions":
             return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                               action='manage_repository_reviews',
                                                               **kwd ) )
         if operation == "view_or_manage_repository":
             return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                               action='view_or_manage_repository',
                                                               **kwd ) )
     return self.reviewed_repositories_i_own_grid( trans, **kwd )
Ejemplo n.º 37
0
 def reset_metadata_on_selected_repositories_in_tool_shed(self, trans, **kwd):
     rmm = repository_metadata_manager.RepositoryMetadataManager(trans.app, trans.user)
     if 'reset_metadata_on_selected_repositories_button' in kwd:
         message, status = rmm.reset_metadata_on_selected_repositories(**kwd)
     else:
         message = escape(util.restore_text(kwd.get('message', '')))
         status = kwd.get('status', 'done')
     repositories_select_field = rmm.build_repository_ids_select_field(name='repository_ids',
                                                                       multiple=True,
                                                                       display='checkboxes',
                                                                       my_writable=False)
     return trans.fill_template('/webapps/tool_shed/common/reset_metadata_on_selected_repositories.mako',
                                repositories_select_field=repositories_select_field,
                                message=message,
                                status=status)
Ejemplo n.º 38
0
 def reset_metadata_on_selected_repositories_in_tool_shed(self, trans, **kwd):
     rmm = repository_metadata_manager.RepositoryMetadataManager(trans.app, trans.user)
     if 'reset_metadata_on_selected_repositories_button' in kwd:
         message, status = rmm.reset_metadata_on_selected_repositories(**kwd)
     else:
         message = escape(util.restore_text(kwd.get('message', '')))
         status = kwd.get('status', 'done')
     repositories_select_field = rmm.build_repository_ids_select_field(name='repository_ids',
                                                                       multiple=True,
                                                                       display='checkboxes',
                                                                       my_writable=False)
     return trans.fill_template('/webapps/tool_shed/common/reset_metadata_on_selected_repositories.mako',
                                repositories_select_field=repositories_select_field,
                                message=message,
                                status=status)
Ejemplo n.º 39
0
 def undelete_repository(self, trans, **kwd):
     message = escape(kwd.get("message", ""))
     id = kwd.get("id", None)
     if id:
         # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id.
         ids = util.listify(id)
         count = 0
         undeleted_repositories = ""
         for repository_id in ids:
             repository = suc.get_repository_in_tool_shed(trans.app, repository_id)
             if repository:
                 if repository.deleted:
                     # Inspect all repository_metadata records to determine those that are installable, and mark
                     # them accordingly.
                     for repository_metadata in repository.metadata_revisions:
                         metadata = repository_metadata.metadata
                         if metadata:
                             if metadata_util.is_downloadable(metadata):
                                 repository_metadata.downloadable = True
                                 trans.sa_session.add(repository_metadata)
                     # Mark the repository admin role as not deleted.
                     repository_admin_role = repository.admin_role
                     if repository_admin_role is not None:
                         repository_admin_role.deleted = False
                         trans.sa_session.add(repository_admin_role)
                     repository.deleted = False
                     trans.sa_session.add(repository)
                     trans.sa_session.flush()
                     if not repository.deprecated:
                         # Update the repository registry.
                         trans.app.repository_registry.add_entry(repository)
                     count += 1
                     undeleted_repositories += " %s" % repository.name
         if count:
             message = "Undeleted %d %s: %s" % (
                 count,
                 inflector.cond_plural(count, "repository"),
                 undeleted_repositories,
             )
         else:
             message = "No selected repositories were marked deleted, so they could not be undeleted."
     else:
         message = "No repository ids received for undeleting."
     trans.response.send_redirect(
         web.url_for(
             controller="admin", action="browse_repositories", message=util.sanitize_text(message), status="done"
         )
     )
Ejemplo n.º 40
0
 def reset_metadata_on_selected_repositories_in_tool_shed(self, trans, **kwd):
     rmm = repository_metadata_manager.RepositoryMetadataManager(trans.app, trans.user)
     if "reset_metadata_on_selected_repositories_button" in kwd:
         message, status = rmm.reset_metadata_on_selected_repositories(**kwd)
     else:
         message = escape(util.restore_text(kwd.get("message", "")))
         status = kwd.get("status", "done")
     repositories_select_field = rmm.build_repository_ids_select_field(
         name="repository_ids", multiple=True, display="checkboxes", my_writable=False
     )
     return trans.fill_template(
         "/webapps/tool_shed/common/reset_metadata_on_selected_repositories.mako",
         repositories_select_field=repositories_select_field,
         message=message,
         status=status,
     )
Ejemplo n.º 41
0
 def reviewed_repositories_i_own(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     # The value of the received id is the encoded repository id.
     if 'operation' in kwd:
         operation = kwd['operation'].lower()
         if operation == "inspect repository revisions":
             return trans.response.send_redirect(
                 web.url_for(controller='repository_review',
                             action='manage_repository_reviews',
                             **kwd))
         if operation == "view_or_manage_repository":
             return trans.response.send_redirect(
                 web.url_for(controller='repository_review',
                             action='view_or_manage_repository',
                             **kwd))
     return self.reviewed_repositories_i_own_grid(trans, **kwd)
Ejemplo n.º 42
0
 def manage_repository_reviews( self, trans, mine=False, **kwd ):
     # The value of the received id is the encoded repository id.
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     repository_id = kwd.get( 'id', None )
     if repository_id:
         repository = suc.get_repository_in_tool_shed( trans.app, repository_id )
         repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False )
         metadata_revision_hashes = [ metadata_revision.changeset_revision for metadata_revision in repository.metadata_revisions ]
         reviewed_revision_hashes = [ review.changeset_revision for review in repository.reviews ]
         reviews_dict = odict()
         for changeset in hg_util.get_reversed_changelog_changesets( repo ):
             ctx = repo.changectx( changeset )
             changeset_revision = str( ctx )
             if changeset_revision in metadata_revision_hashes or changeset_revision in reviewed_revision_hashes:
                 rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, changeset_revision )
                 if changeset_revision in reviewed_revision_hashes:
                     # Find the review for this changeset_revision
                     repository_reviews = \
                         review_util.get_reviews_by_repository_id_changeset_revision( trans.app,
                                                                                      repository_id,
                                                                                      changeset_revision )
                     # Determine if the current user can add a review to this revision.
                     can_add_review = trans.user not in [ repository_review.user for repository_review in repository_reviews ]
                     repository_metadata = suc.get_repository_metadata_by_changeset_revision( trans.app, repository_id, changeset_revision )
                     if repository_metadata:
                         repository_metadata_reviews = util.listify( repository_metadata.reviews )
                     else:
                         repository_metadata_reviews = []
                 else:
                     repository_reviews = []
                     repository_metadata_reviews = []
                     can_add_review = True
                 installable = changeset_revision in metadata_revision_hashes
                 revision_dict = dict( changeset_revision_label=changeset_revision_label,
                                       repository_reviews=repository_reviews,
                                       repository_metadata_reviews=repository_metadata_reviews,
                                       installable=installable,
                                       can_add_review=can_add_review )
                 reviews_dict[ changeset_revision ] = revision_dict
     return trans.fill_template( '/webapps/tool_shed/repository_review/reviews_of_repository.mako',
                                 repository=repository,
                                 reviews_dict=reviews_dict,
                                 mine=mine,
                                 message=message,
                                 status=status )
Ejemplo n.º 43
0
 def select_previous_review( self, trans, **kwd ):
     # The value of the received id is the encoded repository id.
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     repository = suc.get_repository_in_tool_shed( trans.app, kwd[ 'id' ] )
     changeset_revision = kwd.get( 'changeset_revision', None )
     repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False )
     previous_reviews_dict = review_util.get_previous_repository_reviews( trans.app,
                                                                          repository,
                                                                          changeset_revision )
     rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, changeset_revision )
     return trans.fill_template( '/webapps/tool_shed/repository_review/select_previous_review.mako',
                                 repository=repository,
                                 changeset_revision=changeset_revision,
                                 changeset_revision_label=changeset_revision_label,
                                 previous_reviews_dict=previous_reviews_dict,
                                 message=message,
                                 status=status )
Ejemplo n.º 44
0
 def manage_repository_reviews_of_revision( self, trans, **kwd ):
     # The value of the received id is the encoded repository id.
     message = escape( kwd.get( 'message', '' ) )
     status = kwd.get( 'status', 'done' )
     repository_id = kwd.get( 'id', None )
     changeset_revision = kwd.get( 'changeset_revision', None )
     repository = suc.get_repository_in_tool_shed( trans.app, repository_id )
     repo = hg_util.get_repo_for_repository( trans.app, repository=repository, repo_path=None, create=False )
     installable = changeset_revision in [ metadata_revision.changeset_revision for metadata_revision in repository.metadata_revisions ]
     rev, changeset_revision_label = hg_util.get_rev_label_from_changeset_revision( repo, changeset_revision )
     reviews = review_util.get_reviews_by_repository_id_changeset_revision( trans.app,
                                                                            repository_id,
                                                                            changeset_revision )
     return trans.fill_template( '/webapps/tool_shed/repository_review/reviews_of_changeset_revision.mako',
                                 repository=repository,
                                 changeset_revision=changeset_revision,
                                 changeset_revision_label=changeset_revision_label,
                                 reviews=reviews,
                                 installable=installable,
                                 message=message,
                                 status=status )
Ejemplo n.º 45
0
 def delete_repository_metadata(self, trans, **kwd):
     message = escape(kwd.get('message', ''))
     status = kwd.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         for repository_metadata_id in ids:
             repository_metadata = metadata_util.get_repository_metadata_by_id(trans.app, repository_metadata_id)
             trans.sa_session.delete(repository_metadata)
             trans.sa_session.flush()
             count += 1
         if count:
             message = "Deleted %d repository metadata %s" % (count, inflector.cond_plural(len(ids), "record"))
     else:
         message = "No repository metadata ids received for deleting."
         status = 'error'
     trans.response.send_redirect(web.url_for(controller='admin',
                                              action='browse_repository_metadata',
                                              message=util.sanitize_text(message),
                                              status=status))
Ejemplo n.º 46
0
def check_for_updates(app, model, repository_id=None):
    message = ''
    status = 'ok'
    if repository_id is None:
        success_count = 0
        repository_names_not_updated = []
        updated_count = 0
        for repository in model.context.query( model.ToolShedRepository ) \
                                       .filter( model.ToolShedRepository.table.c.deleted == false() ):
            ok, updated = \
                check_or_update_tool_shed_status_for_installed_repository( app, repository )
            if ok:
                success_count += 1
            else:
                repository_names_not_updated.append(
                    '<b>%s</b>' % escape(str(repository.name)))
            if updated:
                updated_count += 1
        message = "Checked the status in the tool shed for %d repositories.  " % success_count
        message += "Updated the tool shed status for %d repositories.  " % updated_count
        if repository_names_not_updated:
            message += "Unable to retrieve status from the tool shed for the following repositories:\n"
            message += ", ".join(repository_names_not_updated)
    else:
        repository = suc.get_tool_shed_repository_by_id(app, repository_id)
        ok, updated = \
            check_or_update_tool_shed_status_for_installed_repository( app, repository )
        if ok:
            if updated:
                message = "The tool shed status for repository <b>%s</b> has been updated." % escape(
                    str(repository.name))
            else:
                message = "The status has not changed in the tool shed for repository <b>%s</b>." % escape(
                    str(repository.name))
        else:
            message = "Unable to retrieve status from the tool shed for repository <b>%s</b>." % escape(
                str(repository.name))
            status = 'error'
    return message, status
Ejemplo n.º 47
0
    def repository_reviews_by_user( self, trans, **kwd ):
        message = escape( kwd.get( 'message', '' ) )
        status = kwd.get( 'status', 'done' )

        if 'operation' in kwd:
            operation = kwd['operation'].lower()
            # The value of the received id is the encoded review id.
            review = review_util.get_review( trans.app, kwd[ 'id' ] )
            repository = review.repository
            kwd[ 'id' ] = trans.security.encode_id( repository.id )
            if operation == "inspect repository revisions":
                return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                                  action='manage_repository_reviews',
                                                                  **kwd ) )
            if operation == "view_or_manage_repository":
                kwd[ 'changeset_revision' ] = review.changeset_revision
                return trans.response.send_redirect( web.url_for( controller='repository_review',
                                                                  action='view_or_manage_repository',
                                                                  **kwd ) )
        # The user may not be the current user.  The value of the received id is the encoded user id.
        user = suc.get_user( trans.app, kwd[ 'id' ] )
        self.repository_reviews_by_user_grid.title = "All repository revision reviews for user '%s'" % user.username
        return self.repository_reviews_by_user_grid( trans, **kwd )
Ejemplo n.º 48
0
 def get_value( self, trans, grid, quota ):
     if quota.description:
         return escape(quota.description)
     return ''
Ejemplo n.º 49
0
 def get_value( self, trans, grid, user ):
     return escape(user.email)
Ejemplo n.º 50
0
 def get_value( self, trans, grid, quota ):
     return escape(quota.name)
Ejemplo n.º 51
0
 def get_value( self, trans, grid, user ):
     if user.username:
         return escape(user.username)
     return 'not set'
Ejemplo n.º 52
0
 def view_tool_data_tables( self, trans, **kwd ):
     message = escape( galaxy.util.restore_text( kwd.get( 'message', '' ) ) )
     status = galaxy.util.restore_text( kwd.get( 'status', 'done' ) )
     return trans.fill_template( 'admin/view_data_tables_registry.mako', message=message, status=status )