Ejemplo n.º 1
0
def read_and_create(url, xml_files, drop=False, echo=False):
    engine, session = get_engine_session(url, echo=echo)
    
    if drop:
        metadata.drop_all(bind=engine) # cleans the table (for debugging)
        metadata.create_all(bind=engine)
    
    number_of_files = len(xml_files)
    for (counter, file_) in enumerate(xml_files):
        try:
            insert_analysis(session, file_)
        except Exception as e:
            print("Error in file %s" % file_)
            print(e)
        
        # % counter:
        sys.stdout.write(str(int(float(counter + 1)
                                 / float(number_of_files) * 100)))
        sys.stdout.write(" %")
        sys.stdout.write("\r")
        sys.stdout.flush()
    
    sys.stdout.write("\n")
    
    session.remove()
Ejemplo n.º 2
0
class CustomFlask(Flask):
    # we deal with jinja2 options to remove whitespace
    jinja_options = dict(
        Flask.jinja_options, trim_blocks=True, lstrip_blocks=True)

app = CustomFlask(__name__)

# Configuration
from firewoes.web import webconfig_default
app.config.from_object(webconfig_default)

if "FIREWOES_CONFIG" in os.environ:
    app.config.from_envvar('FIREWOES_CONFIG')

# SQLAlchemy
engine, session = get_engine_session(app.config['DATABASE_URI'],
                                     echo=app.config['SQLALCHEMY_ECHO'])

from frontend.views import mod as frontend_module
app.register_blueprint(frontend_module)

# 404 / 500 errors

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

@app.errorhandler(500)
def server_error(e):
    app.logger.error(e)
    return render_template('500.html'), 500
#     """
#     try:
#         session.execute(metadata.tables["debian_package_people_mapping"].delete())
#         session.execute(metadata.tables["debian_packages"].delete())
#         session.execute(metadata.tables["debian_maintainers"].delete())
#         session.commit()
#     except:
#         pass


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Recreates content in Debian\
    tables, related to packages, maintainers and the link between them. The\
    information comes from a file through ftp.")
                                     
    parser.add_argument("db_url", help="URL of the database")
    parser.add_argument("--verbose", help="outputs SQLAlchemy requests",
                        action="store_true")
    args = parser.parse_args()

    engine, session = get_engine_session(args.db_url, echo=args.verbose)
    
    metadata.drop_all(engine)
    metadata.create_all(engine)

    
    # ftp connection, db insertion
    ftpo = ftp_connect(url)
    generate_packages_for_people(ftpo, path, session)
    ftp_close(ftpo)