1
+ #!/usr/bin/env python
2
+ # vim: ai ts=4 sts=4 et sw=4 encoding=utf-8
3
+
1
4
import os
2
5
import sys
3
6
import csv
@@ -20,55 +23,41 @@ class Main:
20
23
save = True
21
24
template = ""
22
25
submit = False
23
-
26
+
24
27
def __init__ (self ):
25
28
''' Get arguments '''
26
29
args = sys .argv
27
30
if len (args ):
28
31
try :
29
32
self .format = args [1 ].lower ()
30
33
self .file_name = args [2 ]
31
- self .save = args [4 ]
32
34
self .template = args [3 ]
33
- self .submit = args [5 ]
34
35
except :
35
36
self .format = ""
36
37
self .file_name = ""
37
- self .save = True
38
38
self .template = ""
39
- self .submit = False
40
39
41
- if self .format not in ('csv' , 'dict' ):
40
+ if self .format not in ('csv' ):
42
41
self .help ()
43
42
else :
44
- if self .format == 'csv' :
45
- if not check_file (self .file_name , "csv" ):
46
- print "Invalid file location or file does not exist." \
47
- "Check if it has a .csv extenion"
48
- else :
49
- self .export_csv ()
50
- if self .format == 'dict' :
51
- print "Working on data dictionary"
43
+ if not check_file (self .file_name , "csv" ):
44
+ print "Invalid file location or file does not exist." \
45
+ "Check if it has a .csv extenion"
46
+ else :
47
+ self .export_csv ()
52
48
else :
53
49
self .help ()
54
50
55
-
56
51
def help (self ):
57
52
print (u"------------------------------------------\n "
58
53
"GENERATE CASEXML USING DATA AND TEMPLATE \n "
59
54
"------------------------------------------\n "
60
55
"Contains function to generate Casexml and save or \n "
61
56
"submit to CommcareHq\n "
62
- "To run:\n $ python casexml.py datasource_type filename template "
63
- "save=True/False submit=True/False\n \n OPTIONS:\n -------- \n "
64
- "datasource_type Type of data Source. can be either csv, "
65
- "dictionary(data) \n "
66
- "filename Fullname of the file holding data., "
67
- " Incase of dictionary, pass the dictionary \n "
68
- "template Template Name, including .xml extension\n "
69
- "save If to save xml output or not. Forms "
70
- "are stored in output directory" )
71
-
57
+ "To run:\n $ python casexml.py csvfile template "
58
+ "\n \n OPTIONS:\n -------- \n "
59
+ "csvfile A full path of csv file to be exported to"
60
+ " CommcareHQ " )
72
61
73
62
def export_csv (self ):
74
63
info = {}
@@ -77,22 +66,22 @@ def export_csv(self):
77
66
print "Template doesnot exist, or invalid template. Check if " \
78
67
"it has a .xml extenion"
79
68
return 0
80
-
69
+
81
70
try :
82
71
data = csv .reader (open (self .file_name , 'rb' ))
83
72
except :
84
73
print "Data doesnt exist"
85
-
86
- #Remove Header
74
+
75
+ #Remove Header
87
76
header = data .next ()
88
77
info = {}
89
78
#Loop through each row and get data
90
79
for x in data :
91
80
for label , value in zip (header , x ):
92
81
info [label ] = value
93
-
82
+
94
83
form = CaseXMLInterface (info , self .template )
95
- # save_casexmlform(self, form)
84
+ save_casexmlform (form )
96
85
transmit_form (form )
97
86
98
87
0 commit comments