Beispiel #1
0
 def default(self, *args):
     if len(args) < 1:
         controller.http_redirect(controller.base_url())
     app_name = args[0].replace('+',' ')        
     application = Application.query.filter_by(name = app_name).first()
     if not application:
         application = Application.query.filter_by(\
             source_package = app_name).first()
     if not application:
         controller.http_redirect(controller.base_url())            
         
     # Get dict of the latest version for each distro release
     last_version_dict = {}        
     last_package = None    
     for plist in PackageList.query.all():
         if plist.suite.endswith('-testing'):
             continue
         package = Package.query.filter(and_(Package.lists.any(id=plist.id), 
             or_(Package.package==application.source_package, Package.source==application.source_package),
             Package.install_class=='M'))\
             .order_by(desc(Package.last_modified)).first()
         if package:
             last_version_dict[plist.version] = package.version
             last_package = package  
     return template.render("software.html", app=application,
                            last_version_dict=last_version_dict, 
                            package=last_package)
Beispiel #2
0
 def index(self, name=None, password = None, referer=None):
     if name: # submitting
         user = User.query.filter_by(username = name).first()
         if user and user.password == userinfo.md5pass(password, user.password):
             if user.auth == 1:
                 userinfo.set_login_sesion_info(user)
                 if referer:
                     controller.http_redirect(referer)
                 else:
                     controller.http_redirect(controller.base_url()+'/welcome/')
             else:
                 return template.render("login.html" 
                     , error_reason = "auth" 
                     , referer = referer 
                     )                    
         else:                
             return template.render("login.html"
                 , error_reason = "failed" 
                 , referer = referer 
                 )
     else:
         referer = controller.get_header('Referer')
         if not referer:
             referer = controller.base_url()+"/welcome/"
         return template.render("login.html"
             , hide_login_register = True
             , referer = referer
             , error_reason = None)
Beispiel #3
0
    def default(self, *args):
        if len(args) < 1:
            controller.http_redirect(controller.base_url())
        app_name = args[0].replace('+', ' ')
        application = Application.query.filter_by(name=app_name).first()
        if not application:
            application = Application.query.filter_by(\
                source_package = app_name).first()
        if not application:
            controller.http_redirect(controller.base_url())

        # Get dict of the latest version for each distro release
        last_version_dict = {}
        downloads = {}
        last_package = None
        for plist in PackageList.query.all():
            if plist.suite.endswith('-testing'):
                continue
            package = Package.query.filter(and_(Package.lists.any(id=plist.id),
                or_(Package.package==application.source_package, Package.source==application.source_package),
                Package.install_class=='M'))\
                .order_by(desc(Package.last_modified)).first()
            if package:
                last_version_dict[plist.version] = package.version
                downloads[upstreamVersion(
                    package.version)] = package.download_count
                last_package = package
        return template.render("software.html",
                               app=application,
                               last_version_dict=last_version_dict,
                               downloads=downloads,
                               package=last_package)
Beispiel #4
0
 def edit(self, for_package_id = None, from_app_id = None):
     """ 
     Add/Edit an application record, after submission the browser
     will be redirected to the referer page
     """        
     if not userinfo.is_admin():
         controller.http_redirect(controller.base_url()+'/login/')
 
     # We need these to fill the combo box
     # do it here to avoid autoflush later
     categories = ApplicationsCategory.query.all()
     
     source_package = None
     application = None
     # the app info can be loaded from an app_id or for a package id
     if from_app_id:
         application = app_by_id(from_app_id)
         if not application:
             return "Application ID not found"
     elif for_package_id:
         package_id = for_package_id
         package = Package.query.filter_by(id = package_id).one()
         if not package:
             return "Package id %d not found" % package_id
         source_package = package.source or package.package
         
     if source_package: # we got a package hint
         application = Application.query.filter_by(\
             source_package = source_package).first()
 
     if not application: # app was not found, create new
         application = Application()
         application.source_package = source_package
 
     # Automatically set app name to source package
     # usefull hint on "for_package_id"                    
     if not application.name:
         application.name = source_package        
 
     # No changes here, save will be performed on edit_submit
     database.rollback()
     if sa_version.split(".") < ["0", "5", "0"]:
         database.clear()
     
     # Set the screenshot filename
     screenshot_filename = ""
     id = application.id
     if id:
         screenshot_filename = "/media/screens/%d/%d_t.png" % (id, id)            
     return template.render("app_edit.html" \
         , application = application \
         , categories = categories \
         , screenshot_filename = screenshot_filename \
     )
Beispiel #5
0
    def edit(self, for_package_id=None, from_app_id=None):
        """ 
        Add/Edit an application record, after submission the browser
        will be redirected to the referer page
        """
        if not userinfo.is_admin():
            controller.http_redirect(controller.base_url() + '/login/')

        # We need these to fill the combo box
        # do it here to avoid autoflush later
        categories = ApplicationsCategory.query.all()

        source_package = None
        application = None
        # the app info can be loaded from an app_id or for a package id
        if from_app_id:
            application = app_by_id(from_app_id)
            if not application:
                return "Application ID not found"
        elif for_package_id:
            package_id = for_package_id
            package = Package.query.filter_by(id=package_id).one()
            if not package:
                return "Package id %d not found" % package_id
            source_package = package.source or package.package

        if source_package:  # we got a package hint
            application = Application.query.filter_by(\
                source_package = source_package).first()

        if not application:  # app was not found, create new
            application = Application()
            application.source_package = source_package

        # Automatically set app name to source package
        # usefull hint on "for_package_id"
        if not application.name:
            application.name = source_package

        # No changes here, save will be performed on edit_submit
        database.rollback()
        if sa_version.split(".") < ["0", "5", "0"]:
            database.clear()

        # Set the screenshot filename
        screenshot_filename = ""
        id = application.id
        if id:
            screenshot_filename = "/media/screens/%d/%d_t.png" % (id, id)
        return template.render("app_edit.html" \
            , application = application \
            , categories = categories \
            , screenshot_filename = screenshot_filename \
        )
Beispiel #6
0
	def index(self, user = None, key = None):
		if not user or not key:
			return "Direct access is not allowed"
		user = User.query.filter_by(username = user, authkey = key).first()
		if user:
			user.auth = 1
			user.authkey = None
			userinfo.set_login_sesion_info(user)		
			controller.http_redirect(controller.base_url()+ "/welcome/")	
            
		return "Auth key or user are no longer valid!"
Beispiel #7
0
    def index(self, q=None):
        """
		The is the main page which presents the list of packages
		if no key (q) is specified only the packages needing an action
		are shown.
		"""
        if not userinfo.is_admin():
            controller.http_redirect(controller.base_url() + '/login')

        class Stats():
            total = 0
            unclassified = 0
            unlinked = 0

        if q:
            db_packages = Package.query.filter_by(package=q).order_by(\
             asc(Package.version), asc(Package.package)).all()
        else:
            db_packages = Package.query.order_by( \
             asc(Package.version), asc(Package.package)).all()
        packages = {}
        last_package_version = None
        stats = Stats()

        # Walk the packages list, skip classified and linked
        for package in db_packages:
            package_version = package.package + "-" + package.version
            source_package = package.source or package.package
            if package_version == last_package_version:
                continue
            if len(package.lists) == 0:  # package is not in a repos
                continue
            last_package_version = package_version
            stats.total += 1
            app = None
            if package.install_class == None:
                stats.unclassified += 1
            elif package.install_class == 'M':
                app = Application.query.filter_by(
                    source_package=source_package).first()
                if not app:
                    stats.unlinked += 1
            if q or not package.install_class or \
             (package.install_class=='M' and not app):
                if not source_package in packages.keys():
                    packages[source_package] = []
                packages[source_package].append(package)
        ordered_packages = OrderedDict(
            sorted(packages.items(), key=lambda t: t[0]))
        return template.render("packages.html",
                               packages=ordered_packages,
                               stats=stats,
                               q=q)
Beispiel #8
0
	def index(self, q=None):
		"""
		The is the main page which presents the list of packages
		if no key (q) is specified only the packages needing an action
		are shown.
		"""
		if not userinfo.is_admin():
			controller.http_redirect(controller.base_url()+'/login')

		class Stats():
			total = 0
			unclassified = 0
			unlinked = 0

		if q:
			db_packages = Package.query.filter_by(package=q).order_by(\
				asc(Package.version), asc(Package.package)).all()
		else:
			db_packages = Package.query.order_by( \
				asc(Package.version), asc(Package.package)).all()
		packages = {}
		last_package_version = None
		stats = Stats()

		# Walk the packages list, skip classified and linked
		for package in db_packages:
			package_version = package.package+"-"+package.version
			source_package = package.source or package.package
			if package_version == last_package_version:
				continue
			if len(package.lists) == 0: # package is not in a repos
				continue
			last_package_version = package_version
			stats.total += 1
			app = None
			if package.install_class == None:
				stats.unclassified += 1
			elif package.install_class == 'M':
				app = Application.query.filter_by(
					source_package = source_package
				).first()
				if not app:
					stats.unlinked += 1
			if q or not package.install_class or \
				(package.install_class=='M' and not app):
					if not source_package in packages.keys():
						packages[source_package] = []
					packages[source_package].append(package)
		ordered_packages=OrderedDict(sorted(packages.items(), key=lambda t: t[0]))
		return template.render("packages.html", packages = ordered_packages
			, stats = stats, q=q
		)
Beispiel #9
0
    def edit_submit(self, id, source_package, name, homepage, license, \
        descr, video_link, category):
        """ 
        Add/Edit an application record - submit
        """
        if not userinfo.is_admin():
            controller.http_redirect(controller.base_url() + '/login/')

        # Keep category query on top to avoid autoflush
        cat = ApplicationsCategory.query.filter_by(name=category).first()

        application = app_by_id(id) or Application()
        application.source_package = source_package or None
        application.name = name
        application.homepage = homepage
        application.descr = descr.decode('utf-8')
        application.license = license
        application.video_link = video_link
        if cat:
            application.category = cat
        else:
            return "ERROR: Could not find category", category

        try:
            database.commit()
        except IntegrityError as e:
            session.rollback()
            return "ERROR: Unable to update"

        id = application.id
        # db operation was succesful, update the screenshot if submited
        username = controller.session('login_username')
        filename = os.path.join(apt_portal.base_dir,
                                '../media/screens/%s_upload.png' % username)
        thumb_filename = os.path.join(
            apt_portal.base_dir, '../media/screens/%s_upload_t.png' % username)
        # There is a screenshot image to be uploaded
        if os.path.exists(filename):
            screen_img_dir = os.path.join(apt_portal.base_dir,
                                          "../media/screens/%d" % id)
            if not os.path.isdir(screen_img_dir):
                os.makedirs(screen_img_dir, 0755)
            dest = "%s/%s.png" % (screen_img_dir, id)
            thumb_dest = "%s/%d_t.png" % (screen_img_dir, id)
            os.rename(filename, dest)
            os.chmod(dest, 0644)
            os.rename(thumb_filename, thumb_dest)
            os.chmod(thumb_dest, 0644)
        return "OK " + str(application.id)
Beispiel #10
0
 def edit_submit(self, id, source_package, name, homepage, license, \
     descr, video_link, category):
     """ 
     Add/Edit an application record - submit
     """
     if not userinfo.is_admin():
         controller.http_redirect(controller.base_url()+'/login/')
             
     # Keep category query on top to avoid autoflush
     cat = ApplicationsCategory.query.filter_by(name=category).first()
     
     application = app_by_id(id) or Application()            
     application.source_package = source_package or None
     application.name = name
     application.homepage = homepage
     application.descr = descr.decode('utf-8')
     application.license = license
     application.video_link = video_link        
     if cat:
         application.category = cat
     else:
         return "ERROR: Could not find category", category                
     
     try:            
         database.commit()
     except IntegrityError as e:
         session.rollback()
         return "ERROR: Unable to update"
     
     id = application.id
     # db operation was succesful, update the screenshot if submited
     username = controller.session('login_username')
     filename = os.path.join(apt_portal.base_dir  , '../media/screens/%s_upload.png' % username)
     thumb_filename = os.path.join(apt_portal.base_dir, '../media/screens/%s_upload_t.png' % username)
     # There is a screenshot image to be uploaded
     if os.path.exists(filename):                
         screen_img_dir  = os.path.join(apt_portal.base_dir, "../media/screens/%d" % id)
         if not os.path.isdir(screen_img_dir):
             os.makedirs(screen_img_dir, 0755)                            
         dest = "%s/%s.png" % (screen_img_dir, id)
         thumb_dest = "%s/%d_t.png" % (screen_img_dir, id)
         os.rename(filename, dest)                
         os.chmod(dest, 0644)                    
         os.rename(thumb_filename, thumb_dest)
         os.chmod(thumb_dest, 0644)    
     return "OK "+str(application.id)
Beispiel #11
0
    def default(self, *args, **kwargs):
        """ 
        @summary: handles the following urls:
            http://base_url/updates/distribution/release/
            with the following keywords:
                q = seach keyword
                page = starting page
                category = apps from category
            Or to check the latest update for a specific releasE:
                http://base_url/updates/distribution/release/appname            
        """
        argc = len(args)
        if argc != 2:
            controller.http_redirect(controller.base_url()+"/updates/Ubuntu/"\
                                     +controller.current_release)
        distro = args[0]
        release = args[1]

        return updates_page(distro, release, **kwargs)
Beispiel #12
0
    def default(self, *args, **kwargs):
        """ 
        @summary: handles the following urls:
            http://base_url/updates/distribution/release/
            with the following keywords:
                q = seach keyword
                page = starting page
                category = apps from category
            Or to check the latest update for a specific releasE:
                http://base_url/updates/distribution/release/appname            
        """
        argc = len(args)
        if argc != 2:
            controller.http_redirect(controller.base_url()+"/updates/Ubuntu/"\
                                     +controller.current_release)
        distro = args[0]
        release = args[1]

        return updates_page(distro, release, **kwargs)
Beispiel #13
0
 def index(self, name = None, email = None, comment = None):
     if not name:
         return template.render("contact.html")
     # server side input validation
     if not email:
         return "Email is missing"
     if not comment or len(comment)<10:
         return "Comment is missing"
     if not userinfo.validateEmail(email):            
         return "Invalid email"  
     referer = controller.get_header('Referer')
     if not referer or not referer.startswith(controller.base_url()):
         return "Not Allowed"		
     contact_recipient = apt_portal.get_config("mail", "contact_recipient")
     id = int(time.time())
     template.sendmail('contact.mail'\
 		, sender = '"%s" <%s>' % (name, email)
 		, destination = contact_recipient
 		, comment = comment
         , app_name = apt_portal.app_name
         , id = id
 	)  
     return template.render("contact.html", contact_received=1)
Beispiel #14
0
def render(template_name, **kwargs):
    global _template_lookup, _media_base_url
    mytemplate = _template_lookup.get_template(template_name)
    
    # Global functions
    kwargs["_"] = _
    kwargs["session"] = controller.session 

    # Check if we need to use a lang prefix
    kwargs["pagename"] = pagename()
    kwargs["base_url"] = controller.base_url()
    kwargs["self_url"] = controller.self_url()
    kwargs["release"] = controller.selected_release
    kwargs["media_base_url"] = _media_base_url
    kwargs["current_release"] = controller.current_release
    kwargs["login_username"] = controller.session('login_username')    
    
    start_t = time.time()
    template_output = mytemplate.render(**kwargs)
    stop_t =  time.time()
    if not template_name.endswith('.mail'):
        template_output += '\n<!-- Template %s rendering took %0.3f ms -->\n' % \
            (template_name, (stop_t-start_t)*1000.0)
    return template_output
Beispiel #15
0
def updates_page(distro, release, **kwargs):
    """ Builds the updates page """

    try:
        page = int(kwargs.get("page", 1))
    except ValueError:
        page = 1
    updates_release = release
    q = kwargs.get("q", None)
    category_name = kwargs.get("category", None)
    format = kwargs.get("format", None)
    category = None
    categories = ApplicationsCategory.query.all()
    if category_name:
        category = ApplicationsCategory.query.filter_by(
            name=category_name).first()
        if not category:
            controller.http_redirect(controller.base_url()+"/updates/Ubuntu/" + \
                controller.current_release)
    codename = distroinfo.get_codename(distro, release)
    if format == "xml":
        items_per_page = 100
    else:
        items_per_page = 5
    (applications_list, package_dict, page_count) = \
        packages.get_applications_list(q = q, category = category, page = page
                                        , release = release , items_per_page = items_per_page
                                        )

    # Determine the "Available for" releases
    available_for = {}
    for app in applications_list:
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        available_for[app.id] = {}
        available_for[app.id] = []
        for packagelist in package.lists:
            if packagelist.version not in available_for[app.id]:
                available_for[app.id].append(packagelist.version)

    # Build the changelogs urls
    changelogs_dict = {}
    for app in applications_list:
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        source_package = package.source or package.package
        if source_package[:3] == 'lib':
            prefix = source_package[:4]
        else:
            prefix = source_package[:1]

        changelogs_dict[app.id] = '%s/%s/%s_%s_source.changelog' % \
            (prefix, source_package, source_package, package.version)

    # get the download stats
    download_stats = packages.get_download_stats()

    search_str = controller.self_url() + "?"
    param_str = ''
    for key, value in kwargs.iteritems():
        if key == "page":
            continue
        param_str += key + '=' + value + '&amp;'
    if param_str:
        search_str = controller.self_url() + '?' + param_str
    if format == "xml":
        return template.render('updates.xml',
                               applications_list=applications_list,
                               package_dict=package_dict,
                               available_for=available_for,
                               updates_release=updates_release,
                               changelogs_dict=changelogs_dict)
    else:
        return template.render('updates.html',
                               categories=categories,
                               applications_list=applications_list,
                               package_dict=package_dict,
                               available_for=available_for,
                               page=page,
                               page_count=page_count,
                               q=q,
                               category=category,
                               search_str=search_str,
                               updates_release=updates_release,
                               codename=codename,
                               changelogs_dict=changelogs_dict,
                               download_stats=download_stats)
Beispiel #16
0
def updates_page(distro, release, **kwargs):
    """ Builds the updates page """
    
    try:
        page = int(kwargs.get("page", 1))
    except ValueError:
        page = 1
    updates_release = release                        
    q = kwargs.get("q", None)    
    category_name = kwargs.get("category", None)
    format = kwargs.get("format", None)
    category = None    
    categories = ApplicationsCategory.query.all() 
    if category_name:
        category = ApplicationsCategory.query.filter_by(name=category_name).first()
        if not category:
            controller.http_redirect(controller.base_url()+"/updates/Ubuntu/" + \
                controller.current_release)
    codename = distroinfo.get_codename(distro, release) 
    if format == "xml":
        items_per_page = 100
    else:
        items_per_page = 5
    (applications_list, package_dict, page_count) = \
        packages.get_applications_list(q = q, category = category, page = page 
                                        , release = release , items_per_page = items_per_page
                                        )
                        
    # Determine the "Available for" releases 
    available_for = {}
    for app in applications_list:        
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        available_for[app.id] = {}
        available_for[app.id] = []
        for packagelist in package.lists:
            if packagelist.version not in available_for[app.id]:
                available_for[app.id].append(packagelist.version)  
    
    # Build the changelogs urls
    changelogs_dict ={}
    for app in applications_list:        
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        source_package = package.source or package.package             
        if source_package[:3] == 'lib':
            prefix = source_package[:4]
        else:
            prefix = source_package[:1]
        
        changelogs_dict[app.id] = '%s/%s/%s_%s_source.changelog' % \
            (prefix, source_package, source_package, package.version)

    # get the download stats
    download_stats = packages.get_download_stats()

    search_str = controller.self_url()+"?"
    param_str = ''
    for key,value in kwargs.iteritems():
        if key == "page": 
            continue        
        param_str += key + '=' + value + '&amp;'
    if param_str:
        search_str = controller.self_url()+ '?' + param_str
    if format == "xml":
        return template.render('updates.xml' 
            , applications_list = applications_list
            , package_dict = package_dict 
            , available_for = available_for    
            , updates_release = updates_release 
            , changelogs_dict = changelogs_dict                    
        )
    else: 
        return template.render('updates.html'
            , categories = categories 
            , applications_list = applications_list 
            , package_dict = package_dict 
            , available_for = available_for 
            , page = page 
            , page_count = page_count 
            , q = q 
            , category = category 
            , search_str = search_str
            , updates_release = updates_release
            , codename = codename
            , changelogs_dict = changelogs_dict
            , download_stats=download_stats
    )
Beispiel #17
0
	def index(self,):		
		controller.delete_session()
		raise controller.http_redirect(controller.base_url()+'/welcome')