Skip to content
module.py 98.5 KiB
Newer Older
    """
        Route to push all segments to PiAnoS.
    """
    return jsonify( {
        "error": not do_pianos_copy_all_segments()
    } )

def do_pianos_copy_all_segments():
    """
        Copy all segments images to PiAnoS. If the case already exists, the image is not pushed to PiAnoS.
    """
    try:
        folder_id = config.pianosdb.create_folder( "Annotation" )
        
        img = Image.new( "L", ( 200, 200 ), 255 )
        empty_img_res = 500
        empty_img_id = config.pianosdb.create_image( "PRINT", img, empty_img_res, "empty" )
        
        sql = """
            SELECT files_segments.uuid, files_segments.data, files_v.resolution
            FROM files_segments
            LEFT JOIN files_v ON files_segments.tenprint = files_v.uuid
        """
        for segment in config.db.query_fetchall( sql ):
            img = str2img( segment[ "data" ] )
            try:
                config.pianosdb.create_exercise( 
                    folder_id,
                    segment[ "uuid" ], "",
                    img, segment[ "resolution" ],
                    empty_img_id, empty_img_res
                )
            except caseExistsInDB:
                continue
            except:
                raise
        
        config.pianosdb.commit()
################################################################################
#    Home page

@app.route( baseurl + "/" )
def home():
    """
        Serve the homepage to all users.
    """
    return my_render_template( "index.html" )
################################################################################
#    Main application configuration
gpg = gnupg.GPG( **config.gpg_options )

for key_file in os.listdir( config.keys_folder ):
    with open( config.keys_folder + "/" + key_file, "r" ) as fp:
        gpg.import_keys( fp.read() )

account_type_id_name = {}
sql = "SELECT id, name FROM account_type"
for at in config.db.query_fetchall( sql ):
    account_type_id_name[ at[ "id" ] ] = at[ "name" ]