~rick-rickspencer3/+junk/fairesdescourses

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os.path
import shutil


#check our switches to see if we are qmltestrunner or ap
parser = argparse.ArgumentParser(description='Sets up U1db database files for testing')
parser.add_argument('--test-type',
                   help='choose ap or qml as the test type')
parser.add_argument('--app-namespace',
                    help='specify the app namespace')
parser.add_argument('--db-name',
                     help='specify the name for the u1db')
parser.add_argument('--operation',
                     help='specify startup or teardown')



args = parser.parse_args()
if (args.test_type != 'qml') & (args.test_type != 'ap'):
    print('specify qml or ap as the test type')
    print('exiting without setting up')
    exit(1)

if (args.test_type == 'ap') & (args.app_namespace == None):
    print('Autopilot tests require --namespace')
    print('exiting without setting up')
    exit(1)

if args.db_name == None:
    print('database name (path) for u1db required, use --db-name')
    print('exiting without setting up')
    exit(1)

if (args.operation != "setup") & (args.operation != "teardown"):
    print('specify setup or teardown with --operation')

app_namespace = "qmltestrunner"
if args.test_type !=  "qml":
    app_namespace = args.app_namespace

#assemble the path to the directory and database
parent_dir = os.path.join(os.getenv("HOME"),".local","share",app_namespace)
db_file = os.path.join(os.getenv("HOME"),".local","share",app_namespace,args.db_name)

if not os.path.exists(parent_dir):
    print(parent_dir + ' does not exist. Assuming first run')
    exit(0)

#check to see if the original database is there
if not os.path.isfile(db_file):
    print(db_file + ' does not exist. Assuming first run')
    exit(0)


if args.operation == "setup":
    #make a back up
    try:
        shutil.copyfile(db_file, db_file + ".bak")
    except Exception, err:
        print("file copy operation failed")
        print(err)
        exit(1)
    print("backup copy of " + db_file + "created")
else:
    #restore backup
    try:
        shutil.copyfile(db_file, db_file + ".tested")
        shutil.move(db_file + ".bak", db_file)
        os.remove(db_file + ".tested")
    except Exception, err:
        print("error restoring database")
        print(err)
        exit(1)
    print (db_file + " restored")