File: insanity-dbmerge

package info (click to toggle)
gst-qa-system 0.0%2Bgit20110920.4750a8e8-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 980 kB
  • sloc: python: 8,498; xml: 855; makefile: 42
file content (83 lines) | stat: -rwxr-xr-x 3,208 bytes parent folder | download
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
80
81
82
83
#!/usr/bin/env python
# GStreamer QA system
#
#       bin/dbmerge.py
#
# Copyright (c) 2008, Edward Hervey <bilboed@bilboed.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

"""
Tool to merge testruns from one DBStorage to another
"""

import sys
from optparse import OptionParser
from insanity.log import initLogging
from insanity.storage.sqlite import SQLiteStorage
from insanity.storage.mysql import MySQLStorage

# Use URI for DBStorage
# mysql://user:password@location/dbname
# sqlite://file/full/location

def make_sqlite_storage(location):
    return SQLiteStorage(path=location, async=False)

def make_mysql_storage(uri):
    kw = MySQLStorage.parse_uri(uri)
    return MySQLStorage(async=False, **kw)

if __name__ == "__main__":
    usage = "usage: %prog"
    parser = OptionParser(usage=usage)
    parser.add_option("-t", "--testrun", dest="testrun",
                      help="Specify a testrun id to merge from",
                      type=int,
                      default=-1)
    parser.add_option("-o", "--origin", dest="origin",
                      help="SQLite DB from which to merge from",
                      type=str, default=None)
    parser.add_option("-s", "--origin-mysql", dest="origin_mysql",
                      help="Mysql DB from which to merge from ([user[:password]@]host[:port][/dbname])",
                      type=str, default=None)
    parser.add_option("-d", "--destination", dest="destination",
                      help="SQLite DB to merge into",
                      type=str, default=None)
    parser.add_option("-y", "--destination-mysql", dest="destination_mysql",
                      help="Mysql DB to merge into ([user[:password]@]host[:port][/dbname])",
                      type=str, default=None)
    (options, args) = parser.parse_args(sys.argv[1:])
    if (not (options.origin or options.origin_mysql)) \
           and (not (options.destination or options.destination_mysql)):
        parser.print_help()
        sys.exit()
    initLogging()
    if options.origin:
        origin = make_sqlite_storage(options.origin)
    elif options.origin_mysql:
        origin = make_mysql_storage(options.origin_mysql)
    if options.destination:
        destination = make_sqlite_storage(options.destination)
    elif options.destination_mysql:
        destination = make_mysql_storage(options.destination_mysql)

    # and finally merge !
    if options.testrun != -1:
        runs = [ options.testrun ]
    else:
        runs = None
    destination.merge(origin, runs)