Repository navigation
Expand file tree
/
Copy pathHDCCDBCopier.py
More file actions
81 lines (65 loc) · 3.09 KB
/
Copy pathHDCCDBCopier.py
File metadata and controls
81 lines (65 loc) · 3.09 KB
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
# Class to copy values for a table from one run/variation setting to another
# Uses low-level CCDB API
#
# Author: Sean Dobbs (s-dobbs@northwestern.edu), 2015
import ccdb
from ccdb import Directory, TypeTable, Assignment, ConstantSet
from ccdb.cmd.console_context import ConsoleContext
class HDCCDBCopier:
def __init__(self,ccdb_connect_str=None,run=0,variation="default",verbosity=None,ccdb_username=None):
if verbosity is None:
self.VERBOSE = 1
else:
self.VERBOSE = verbosity
if ccdb_username is None:
# not going to save this for now
ccdb_username = "anonymous"
# save defaults for copy command
self.run = run
self.variation = variation
# force users to set the CCDB connection by hand
# so that we don't accidentally hit the MySQL master too hard
if ccdb_connect_str is None:
raise RuntimeError("Need to set CCDB connection!")
# create CCDB api class
self.ccdb_connect_str = ccdb_connect_str
self.provider = ccdb.AlchemyProvider() # this class has all CCDB manipulation functions
self.provider.connect(ccdb_connect_str) # use usual connection string to connect to database
self.provider.authentication.current_user_name = ccdb_username # to have a name in logs
if self.VERBOSE>0:
print "Created HDCCDBCopier object:"
print " CCDB: %s"%self.ccdb_connect_str
print " Source run = %d"%self.run
print " Source variation = %s"%self.variation
def CopyTable(self,tablename,dest_minrun=0,dest_maxrun=None,dest_variation="default",dest_comment=None,src_run=None,src_variation=None):
"""
Copy table from one run/variation to another using low-level API
"""
# set destination defaults
if dest_comment is None:
dest_comment =""
if dest_maxrun is None:
dest_maxrun = dest_minrun
# allow overriding source defaults
if src_run is None:
src_run = self.run
if src_variation is None:
src_variation = self.variation
if self.VERBOSE>0:
print "copying %s:%d:%s -> %s:%d:%s"%(tablename,src_run,src_variation,tablename,dest_minrun,dest_variation)
# get the source table
src_assignment = self.provider.get_assignment(tablename, src_run, src_variation)
if self.VERBOSE>1:
print str(src_assignment)
if self.VERBOSE>2:
print(src_assignment.constant_set.data_table)
# copy it to the destination
self.provider.create_assignment(data=src_assignment.constant_set.data_table,
path=tablename,
variation_name=dest_variation,
min_run=dest_minrun,
max_run=dest_maxrun,
comment=dest_comment)
if __name__ == "__main__":
# what
print "what"