<s> import os <EOL> import pwd <EOL> import stat <EOL> import time <EOL> from functools import wraps <EOL> from flask import render_template <EOL> from flask import send_file <EOL> from flask import redirect <EOL> from flask import url_for <EOL> from flask import request <EOL> from flask import Response <EOL> from flask import json <EOL> from flask import g <EOL> from . import app <EOL> from backend import cache , Settings , Repository <EOL> settings = Settings ( ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> """<STR_LIT>""" <EOL> if not settings . loaded : <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def get_settings ( ) : <EOL> """<STR_LIT>""" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> return json . dumps ( settings . save ( request . form ) ) <EOL> if request . method == '<STR_LIT:GET>' : <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , ] <EOL> settings . reload ( ) <EOL> g . settings = settings <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_about ( ) : <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , ] <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_help ( ) : <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , ] <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_packages ( ) : <EOL> """<STR_LIT>""" <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : request . path } , ] <EOL> repository = Repository ( settings . basedir ) <EOL> package_list = [ ] <EOL> for dist in repository . list_dists ( ) : <EOL> package_list . extend ( repository . list ( dist [ '<STR_LIT>' ] ) ) <EOL> for package in package_list : <EOL> package [ '<STR_LIT:url>' ] = url_for ( '<STR_LIT>' , codename = package . get ( '<STR_LIT>' ) , <EOL> component = package . get ( '<STR_LIT>' ) , <EOL> architecture = package . get ( '<STR_LIT>' ) , <EOL> package = package . get ( '<STR_LIT>' ) , <EOL> version = package . get ( '<STR_LIT:version>' ) ) <EOL> return render_template ( '<STR_LIT>' , packages = sorted ( package_list ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_repository_detail ( ) : <EOL> """<STR_LIT>""" <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , ] <EOL> repository = Repository ( settings . basedir ) <EOL> codenames = repository . list_dists ( ) <EOL> packages = [ ] <EOL> for dist in repository . list_dists ( ) : <EOL> packages . extend ( repository . list ( dist [ '<STR_LIT>' ] ) ) <EOL> for codename in codenames : <EOL> codename [ '<STR_LIT>' ] = url_for ( '<STR_LIT>' , codename = codename . get ( '<STR_LIT>' , '<STR_LIT:#>' ) ) <EOL> codename [ '<STR_LIT>' ] = len ( [ x for x in packages ] ) <EOL> return render_template ( '<STR_LIT>' , codenames = codenames ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_codename_detail ( codename ) : <EOL> """<STR_LIT>""" <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , <EOL> { '<STR_LIT:name>' : codename , '<STR_LIT:url>' : request . path } , ] <EOL> repository = Repository ( settings . basedir ) <EOL> components = repository . list_components ( codename ) <EOL> packages = repository . list ( codename ) <EOL> if components : <EOL> for c in components : <EOL> c [ '<STR_LIT:url>' ] = url_for ( '<STR_LIT>' , codename = codename , component = c [ '<STR_LIT>' ] ) <EOL> c [ '<STR_LIT:count>' ] = len ( [ x for x in packages if x [ '<STR_LIT>' ] == c [ '<STR_LIT>' ] ] ) <EOL> return render_template ( '<STR_LIT>' , codename = codename , components = components ) <EOL> return render_template ( '<STR_LIT>' , codename = codename ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_component_detail ( codename , component ) : <EOL> """<STR_LIT>""" <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , <EOL> { '<STR_LIT:name>' : codename , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename ) } , <EOL> { '<STR_LIT:name>' : component , '<STR_LIT:url>' : request . path } , ] <EOL> repository = Repository ( settings . basedir ) <EOL> archs = repository . list_architectures ( codename ) <EOL> packages = repository . list ( codename ) <EOL> if archs : <EOL> for a in archs : <EOL> a [ '<STR_LIT:url>' ] = url_for ( '<STR_LIT>' , codename = codename , component = component , architecture = a [ '<STR_LIT>' ] ) <EOL> a [ '<STR_LIT:count>' ] = len ( [ x for x in packages if x [ '<STR_LIT>' ] == component and x [ '<STR_LIT>' ] == a [ '<STR_LIT>' ] ] ) <EOL> return render_template ( '<STR_LIT>' , codename = codename , component = component , archs = archs ) <EOL> return render_template ( '<STR_LIT>' , codename = codename , component = component ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_architecture_detail ( codename , component , architecture ) : <EOL> """<STR_LIT>""" <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , <EOL> { '<STR_LIT:name>' : codename , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename ) } , <EOL> { '<STR_LIT:name>' : component , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename , component = component ) } , <EOL> { '<STR_LIT:name>' : architecture , '<STR_LIT:url>' : request . path } , ] <EOL> repository = Repository ( settings . basedir ) <EOL> repository . options . components = [ str ( component ) ] <EOL> repository . options . architectures = [ str ( architecture ) ] <EOL> package_list = repository . list ( str ( codename ) ) <EOL> repository . options . components = [ ] <EOL> repository . options . architectures = [ ] <EOL> for package in package_list : <EOL> package [ '<STR_LIT>' ] = url_for ( '<STR_LIT>' , codename = package . get ( '<STR_LIT>' ) , <EOL> component = package . get ( '<STR_LIT>' ) , <EOL> architecture = package . get ( '<STR_LIT>' ) , <EOL> package = package . get ( '<STR_LIT>' ) , <EOL> version = package . get ( '<STR_LIT:version>' ) ) <EOL> package [ '<STR_LIT>' ] = url_for ( '<STR_LIT>' , codename = package . get ( '<STR_LIT>' ) , <EOL> component = package . get ( '<STR_LIT>' ) , <EOL> architecture = package . get ( '<STR_LIT>' ) , <EOL> package = package . get ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , packages = sorted ( package_list ) , codename = codename , component = component , architecture = architecture ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_package_versions ( codename , component , architecture , package ) : <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , <EOL> { '<STR_LIT:name>' : codename , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename ) } , <EOL> { '<STR_LIT:name>' : component , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename , component = component ) } , <EOL> { '<STR_LIT:name>' : architecture , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename , component = component , architecture = architecture ) } , <EOL> { '<STR_LIT:name>' : package , '<STR_LIT:url>' : request . path } , ] <EOL> repository = Repository ( settings . basedir ) <EOL> all_versions = repository . list ( codename , package ) <EOL> print all_versions <EOL> return render_template ( '<STR_LIT>' , package = package , versions = all_versions ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_package_detail ( codename , component , architecture , package , version , format = None ) : <EOL> app . logger . info ( request . path ) <EOL> g . breadcrumb = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:url>' : url_for ( '<STR_LIT>' ) } , <EOL> { '<STR_LIT:name>' : codename , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename ) } , <EOL> { '<STR_LIT:name>' : component , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename , component = component ) } , <EOL> { '<STR_LIT:name>' : architecture , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename , component = component , architecture = architecture ) } , <EOL> { '<STR_LIT:name>' : package , '<STR_LIT:url>' : url_for ( '<STR_LIT>' , codename = codename , component = component , architecture = architecture , package = package ) } , <EOL> { '<STR_LIT:name>' : version , '<STR_LIT:url>' : request . path } , ] <EOL> repository = Repository ( settings . basedir ) <EOL> all_versions = repository . list ( codename , package ) <EOL> try : <EOL> reference = cache ( settings ) . read ( repository , codename , component , architecture , package , version ) <EOL> app . logger . debug ( '<STR_LIT>' ) <EOL> except Exception as e : <EOL> app . logger . info ( e ) <EOL> for ref in repository . dumpreferences ( ) : <EOL> if ref [ '<STR_LIT>' ] == package and ref [ '<STR_LIT:version>' ] == version : <EOL> ref [ '<STR_LIT>' ] = os . path . join ( repository . options . basedir , ref [ '<STR_LIT>' ] ) <EOL> try : <EOL> ( mode , ino , dev , nlink , uid , gid , size , atime , mtime , ctime ) = os . stat ( ref [ '<STR_LIT>' ] ) <EOL> ref [ '<STR_LIT>' ] = { '<STR_LIT>' : time . ctime ( mtime ) , '<STR_LIT>' : time . ctime ( ctime ) , '<STR_LIT:user>' : pwd . getpwuid ( uid ) . pw_gecos , '<STR_LIT:size>' : size } <EOL> except Exception as e : <EOL> app . logger . warn ( e ) <EOL> try : <EOL> cache ( settings ) . write ( repository , codename , component , architecture , package , ref [ '<STR_LIT:version>' ] , ref ) <EOL> reference = ref <EOL> except Exception as e : <EOL> app . logger . warn ( '<STR_LIT>' ) <EOL> app . logger . warn ( e ) <EOL> if '<STR_LIT>' in locals ( ) : <EOL> return render_template ( '<STR_LIT>' , package = package , reference = reference , versions = all_versions ) <EOL> return render_template ( '<STR_LIT>' , package = package ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_package_changelog ( codename , component , architecture , package , version ) : <EOL> repository = Repository ( settings . basedir ) <EOL> try : <EOL> reference = cache ( settings ) . read ( repository , codename , component , architecture , package , version ) <EOL> except : <EOL> for ref in repository . dumpreferences ( ) : <EOL> if ref [ '<STR_LIT>' ] == package and ref [ '<STR_LIT:version>' ] == version : <EOL> reference = ref <EOL> if '<STR_LIT>' in locals ( ) : <EOL> reference [ '<STR_LIT>' ] = os . path . join ( repository . options . basedir , reference [ '<STR_LIT>' ] ) <EOL> return json . dumps ( repository . list_changes ( reference [ '<STR_LIT>' ] ) ) <EOL> return json . dumps ( [ ] ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def download_deb ( ** kwargs ) : <EOL> app . logger . debug ( kwargs ) <EOL> repository = Repository ( settings . basedir ) <EOL> ref = cache ( settings ) . read ( repository , kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT:version>' ] ) <EOL> return send_file ( ref [ '<STR_LIT>' ] , as_attachment = True ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def precache_package_detail ( ) : <EOL> def generate ( ) : <EOL> yield '<STR_LIT>' <EOL> repository = Repository ( settings . basedir ) <EOL> for ref in repository . dumpreferences ( ) : <EOL> ref [ '<STR_LIT>' ] = os . path . join ( repository . options . basedir , ref [ '<STR_LIT>' ] ) <EOL> try : <EOL> ( mode , ino , dev , nlink , uid , gid , size , atime , mtime , ctime ) = os . stat ( ref [ '<STR_LIT>' ] ) <EOL> ref [ '<STR_LIT>' ] = { '<STR_LIT>' : time . ctime ( mtime ) , '<STR_LIT>' : time . ctime ( ctime ) , '<STR_LIT:user>' : pwd . getpwuid ( uid ) . pw_gecos , '<STR_LIT:size>' : size } <EOL> cache ( settings ) . write ( repository , ref [ '<STR_LIT>' ] , ref [ '<STR_LIT>' ] , ref [ '<STR_LIT>' ] , ref [ '<STR_LIT>' ] , ref [ '<STR_LIT:version>' ] , ref ) <EOL> yield "<STR_LIT>" <EOL> yield json . dumps ( ref ) <EOL> except Exception as e : <EOL> app . logger . warn ( e ) <EOL> app . logger . warn ( '<STR_LIT>' % ( ref [ '<STR_LIT>' ] , ref [ '<STR_LIT:version>' ] ) ) <EOL> yield json . dumps ( { '<STR_LIT:status>' : '<STR_LIT:OK>' } ) <EOL> return Response ( generate ( ) ) </s>
