Esempio n. 1
0
if not os.path.exists(log_dir):
    print('creating log directory '+log_dir)
    os.makedirs(log_dir)

cur_dir = get_cache_filepath()
if not os.path.exists(cur_dir):
    print('creating cache directory '+cur_dir)
    os.makedirs(cur_dir)

cur_dir = get_kml_filepath()
if not os.path.exists(cur_dir):
    print('creating kml directory '+cur_dir)
    os.makedirs(cur_dir)


print('creating DB at '+get_db_filename())
con = lite.connect(get_db_filename())
with con:
    cur = con.cursor()

    # Logs table (contains information not found in the log file)
    cur.execute("PRAGMA table_info('Logs')")
    columns = cur.fetchall()

    if len(columns) == 0:
        cur.execute("CREATE TABLE Logs("
                "Id TEXT, " # log id (part of the file name)
                "Title TEXT, "
                "Description TEXT, "
                "OriginalFilename TEXT, "
                "Date TIMESTAMP, " # date & time when uploaded
Esempio n. 2
0
#! /usr/bin/env python3

# Script to backup the SQLite DB

from __future__ import print_function
import sys
import os
import datetime

# this is needed for the following imports
sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plot_app'))
from plot_app.config import get_db_filename

db_filename = get_db_filename()
backup_file = "backups/backup_db_"+ \
    datetime.datetime.now().strftime('%Y_%m_%d-%H_%M')

if not os.path.exists('backups'):
    os.mkdir('backups')

os.system('sqlite3 ' + db_filename + ' ".backup ' + backup_file + '.sqlite"')
os.system('sqlite3 ' + db_filename + ' "SELECT * from Logs" >' + backup_file +
          '.sql')
os.system('sqlite3 ' + db_filename + ' "SELECT * from Vehicle" >' +
          backup_file + '_vehicle.sql')

num_lines = sum(1 for line in open(backup_file + '.sql'))
print('Backed up {} records to {}'.format(num_lines, backup_file + '.sqlite'))
#! /usr/bin/env python3

import os
import sys

import sqlite3

# this is needed for the following imports
sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plot_app'))
from plot_app.overview_generator import generate_overview_img_from_id
from plot_app.config import get_db_filename

# get the logs (but only the public ones)
con = sqlite3.connect(get_db_filename(), detect_types=sqlite3.PARSE_DECLTYPES)
cur = con.cursor()
cur.execute('SELECT Id FROM Logs WHERE Public = 1 ORDER BY Date DESC')
db_tuples = cur.fetchall()

for db_row in db_tuples:
    log_id = db_row[0]
    generate_overview_img_from_id(log_id)

cur.close()
con.close()
import os
import argparse

from plot_app.config import get_db_filename

parser = argparse.ArgumentParser(
    description='Remove a DB entry (but not the log file)')

parser.add_argument(
    'log_id',
    metavar='log-id',
    action='store',
    nargs='+',
    help='log id to remove (eg. 8600ac02-cf06-4650-bdd5-7d27ea081852)')

args = parser.parse_args()

con = lite.connect(get_db_filename())
with con:
    cur = con.cursor()
    for log_id in args.log_id:
        print('Removing ' + log_id)
        cur.execute("DELETE FROM LogsGenerated WHERE Id = ?", (log_id, ))
        cur.execute("DELETE FROM Logs WHERE Id = ?", (log_id, ))
        num_deleted = cur.rowcount
        if num_deleted != 1:
            print('Error: not found ({})'.format(num_deleted))
        con.commit()

con.close()