Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: scripts/tools/state_create.py

Issue 2084383003: Move 'buildbot.tac' and 'buildbot' files to a common directory. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Don't ignore .new Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « scripts/tools/make_manhole.py ('k') | third_party/buildbot_8_4p1/buildbot/scripts/runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
ghost stip (do not use) 2016/07/01 01:17:30 seems unrelated to the current change?
dsansome 2016/07/01 01:36:08 It refers to state-template.txt which I also delet
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """A small maintenance tool to do quiet test state creation on test masters."""
7
8 import os
9 import optparse
10 import sys
11 import sqlite3
12 import time
13
14
15 def dump(from_db_filename, to_txt_filename):
16 connection = sqlite3.connect(from_db_filename)
17 with open(to_txt_filename, 'w') as txt_file:
18 for line in connection.iterdump():
19 txt_file.write('%s\n' % line)
20
21
22 def restore(from_txt_filename, to_db_filename):
23
24 with open(from_txt_filename, 'r') as txt_file:
25 try:
26 os.remove(to_db_filename)
27 except OSError as err:
28 if err.errno != 2:
29 raise
30 connection = sqlite3.connect(to_db_filename)
31 cursor = connection.cursor()
32 cursor.executescript(txt_file.read())
33 cursor.close()
34
35
36 def Main(argv):
37 usage = """%prog [options]
38
39 Copy a database to and/or from a text file SQL description.
40 By default, nothing happens, and when both are specified, the
41 dump direction comes first (the database is essentially rebuilt).
42
43 Sample usage:
44 %prog --dump
45 %prog --restore
46 %prog --dump --db master.chromium/state.sqlite --txt=template.txt
47 %prog --dump --restore --yes # see omphaloskepsis
48 """
49
50 parser = optparse.OptionParser(usage=usage)
51 parser.add_option('--dump', action='store_true',
52 help='copy from database to text file')
53 parser.add_option('--restore', action='store_true',
54 help='copy from text file to database')
55 parser.add_option('--yes', action='store_true')
56 parser.add_option('--db', default='state.sqlite',
57 help='sqlite database name')
58 parser.add_option('--txt', default='../state-template.txt',
59 help='filename for text dump')
60 options, args = parser.parse_args(argv)
61
62 if args:
63 parser.error("Found parameters I don't understand: %r" % args)
64 if options.dump and options.restore:
65 print 'Both a dump and a restore. Fun. Hope you meant it.'
66 print 'Will dump first.'
67 if not options.yes:
68 time.sleep(3.14)
69
70 if not options.dump and not options.restore:
71 print 'Neither a dump nor a restore. Boring.'
72
73 if options.dump:
74 dump(options.db, options.txt)
75
76 if options.restore:
77 restore(options.txt, options.db)
78
79
80 if __name__ == '__main__':
81 sys.exit(Main(None))
OLDNEW
« no previous file with comments | « scripts/tools/make_manhole.py ('k') | third_party/buildbot_8_4p1/buildbot/scripts/runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698