Exemplo n.º 1
0
def get_sources_path(session, package, version, config, path):
    ''' Creates a sources_path. Returns exception when it arises
    '''
    location = Location(session, config["SOURCES_DIR"],
                        config["SOURCES_STATIC"], package, version, path)

    file_ = SourceFile(location)

    sources_path = file_.get_raw_url().replace(config['SOURCES_STATIC'],
                                               config['SOURCES_DIR'], 1)
    return sources_path, file_
Exemplo n.º 2
0
def get_sources_path(session, package, version, config, path):
    ''' Creates a sources_path. Returns exception when it arises
    '''
    try:
        location = Location(session, config["SOURCES_DIR"],
                            config["SOURCES_STATIC"], package, version, path)
    except (FileOrFolderNotFound, InvalidPackageOrVersionError) as e:
        raise e

    file_ = SourceFile(location)

    sources_path = file_.get_raw_url().replace(config['SOURCES_STATIC'],
                                               config['SOURCES_DIR'], 1)
    return sources_path, file_
Exemplo n.º 3
0
def get_sources_path(session, package, version, config):
    ''' Creates a sources_path. Returns exception when it arises
    '''
    location = Location(session,
                        config["SOURCES_DIR"],
                        config["SOURCES_STATIC"],
                        package, version, 'debian/copyright')

    file_ = SourceFile(location)

    sources_path = file_.get_raw_url().replace(
        config['SOURCES_STATIC'],
        config['SOURCES_DIR'],
        1)
    return sources_path
Exemplo n.º 4
0
def get_sources_path(session, package, version, config, path):
    """Creates a sources_path. Returns exception when it arises"""
    location = Location(session, config["SOURCES_DIR"],
                        config["SOURCES_STATIC"], package, version, path)

    file_ = SourceFile(location)

    return location.sources_path, file_
Exemplo n.º 5
0
def get_sources_path(session, package, version, config, path):
    ''' Creates a sources_path. Returns exception when it arises
    '''
    try:
        location = Location(session,
                            config["SOURCES_DIR"],
                            config["SOURCES_STATIC"],
                            package, version, path)
    except (FileOrFolderNotFound, InvalidPackageOrVersionError) as e:
        raise e

    file_ = SourceFile(location)

    sources_path = file_.get_raw_url().replace(
        config['SOURCES_STATIC'],
        config['SOURCES_DIR'],
        1)
    return sources_path, file_
Exemplo n.º 6
0
    def _render_file(self, location):
        """
        renders a file
        """
        file_ = SourceFile(location)
        checksum = file_.get_sha256sum(session)
        number_of_duplicates = (qry.count_files_checksum(session, checksum)
                                .first()[0]
                                )
        pkg_infos = Infobox(session,
                            location.get_package(),
                            location.get_version()).get_infos()
        text_file = file_.istextfile()
        raw_url = file_.get_raw_url()
        path = location.get_path_to()

        if self.d.get('api'):
            self.render_func = jsonify
            return dict(type="file",
                        file=location.get_deepest_element(),
                        package=location.get_package(),
                        version=location.get_version(),
                        mime=file_.get_mime(),
                        raw_url=raw_url,
                        path=path,
                        text_file=text_file,
                        stat=qry.location_get_stat(location.sources_path),
                        checksum=checksum,
                        number_of_duplicates=number_of_duplicates,
                        pkg_infos=pkg_infos
                        )
        # prepare the non-api render func
        self.render_func = None
        # more work to do with files
        # as long as 'lang' is in keys, then it's a text_file
        lang = None
        if 'lang' in request.args:
            lang = request.args['lang']
        # if the file is not a text file, we redirect to it
        elif not text_file:
            self.render_func = bind_redirect(raw_url)

        # set render func (non-api form)
        if not self.render_func:
            sources_path = raw_url.replace(
                current_app.config['SOURCES_STATIC'],
                current_app.config['SOURCES_DIR'],
                1)
            # ugly, but better than global variable,
            # and better than re-requesting the db
            # TODO: find proper solution for retrieving souces_path
            # (without putting it in kwargs, we don't want it in
            # json rendering eg)

            # we get the variables for highlighting and message (if they exist)
            try:
                highlight = request.args.get('hl')
            except (KeyError, ValueError, TypeError):
                highlight = None
            try:
                msg = request.args.getlist('msg')
                if msg == "":
                    msg = None  # we don't want empty messages
            except (KeyError, ValueError, TypeError):
                msg = None

            # we preprocess the file with SourceCodeIterator
            sourcefile = SourceCodeIterator(
                sources_path, hl=highlight, msg=msg, lang=lang)

            self.render_func = bind_render(
                self.d['templatename'],
                nlines=sourcefile.get_number_of_lines(),
                pathl=qry.location_get_path_links(".source", path),
                file_language=sourcefile.get_file_language(),
                msgs=sourcefile.get_msgdict(),
                code=sourcefile)

        return dict(type="file",
                    file=location.get_deepest_element(),
                    package=location.get_package(),
                    version=location.get_version(),
                    mime=file_.get_mime(),
                    raw_url=raw_url,
                    path=path,
                    text_file=text_file,
                    stat=qry.location_get_stat(location.sources_path),
                    checksum=checksum,
                    number_of_duplicates=number_of_duplicates,
                    pkg_infos=pkg_infos
                    )