|
Package json_to_relation ::
Module output_disposition
|
|
1 '''
2 Created on Sep 14, 2013
3
4 @author: paepcke
5 '''
6 import csv
7 import sys
8
9
11 '''
12 Specifications for where completed relation rows
13 should be deposited, and in which format. Source
14 options are files, stdout, and a MySQL table.
15
16 Also defined here are available output formats, of
17 which there are two: CSV, and SQL insert statements.
18 '''
20 '''
21 @param outputDest: os file descriptor for output
22 @type outputDest: File
23 '''
24 self.outputDest = outputDest
25
27 return self.outputDest
28
29 - def __exit__(self,excType, excValue, excTraceback):
30 try:
31 self.outputDest.close()
32 except:
33
34
35
36
37 if excValue is None:
38 raise IOError("Could not close the output of the conversion: %s" % sys.exc_info()[0])
39
40
41
42
43
44 return False
45
46
47
51
52
53
56 self.fileHandle = sys.stdout
57
58
59 self.name = "<stdout>"
60 self.csvWriter = csv.writer(sys.stdout, dialect='excel', delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
61
64
66 return "<OutputPipe:<stdout>"
67
69 self.csvWriter.writerow(colElementArray)
70
72 - def __init__(self, fileName, options='ab'):
73
74
75 self.name = fileName
76
77
78 self.fileHandle = open(fileName, options)
79 self.csvWriter = csv.writer(self.fileHandle, dialect='excel', delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
80
82 self.fileHandle.close()
83
85 return "<OutputFile:%s>" % self.name
86
88 self.csvWriter.writerow(colElementArray)
89
91 - def __init__(self, server, pwd, dbName, tbleName):
92 raise NotImplementedError("MySQL connector not yet implemented")
93 self.name = "<MySQL:%s:%s:%s>" % (server,dbName,tbleName)
94 self.server = server
95 self.pwd = pwd
96 self.dbName = dbName
97 self.tbleName = tbleName
98 self.fileHandle = self.connect()
99
101 raise NotImplementedError("MySQL connector not yet implemented")
102
104 raise NotImplementedError("MySQL connector not yet implemented")
105
107 return "<OutputMySQLTable--%s>" % self.name
108
109 - def writerow(self, fd, colElementArray):
110 raise NotImplementedError("MySQL connector not yet implemented")
111