-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmlControl.py
executable file
·144 lines (123 loc) · 4.41 KB
/
cmlControl.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/python
# -*- coding: utf-8 -*-
# freeseer - vga/presentation capture software
#
# Copyright (C) 2013 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# For support, questions, suggestions or any other inquiries, visit:
# http://wiki.github.com/fosslc/freeseer/
import sys
import os
import optparse
import csv
import event
import validurl
import parsecsv
import httpTemplate
from config import *
webuiUsage = """
Usage: ./webuicml [-oim] [file]
-o [folder] : output folder for html files
-i [file] : input csv file for multiple html page
-u : verify input url
"""
welcomeMessage = """
Welcome to webui generator.
Please choose component you want for your webui for live events.
"""
def chooseComponent(componentName):
'''
prompt in the terminal to ask user to choose whether a component should be included in html page
'''
choice = raw_input(componentName + " : (Y/n)\n")
return not choice or choice[0].lower() == 'y'
def readUrl(componentName):
'''
prompt in the terminal to ask user to give url for a component
'''
url = raw_input('Please input the URL for ' + componentName + '\n')
return url
def manualMode(opt):
'''
Handle user input through command line to get url information for a event
'''
print welcomeMessage
eventName = raw_input("name of this event:")
newEvent = event.Event(eventName)
# collect information for each commponent for this event
for com in componentList:
if chooseComponent(com):
url = readUrl(com)
# validate the given url if requested by user
if opt.verifyUrl:
if not validurl.verifyUrl(url):
print "ERROR: " + url + "is not valid. Abort."
newEvent.addUrl(com, url)
return [newEvent]
def csvMode(opt):
'''
handler user input through a csv file to get url information for multiple events
'''
return parsecsv.parseCsv(opt.input, opt.verifyUrl)
def parseargs():
'''
parse the command line option input by users
'''
parser = optparse.OptionParser(version = webuiVersion,
usage = webuiUsage)
parser.add_option('-o', '--output',
dest = 'output', default = 'output/',
help = 'location to store the output html page.')
parser.add_option('-i', '--input',
dest = 'input', default = False,
help = 'input csv file for multiple html page.If not given, will enter manual mode.')
parser.add_option('-u', '--url',
action = 'store_true', dest = 'verifyUrl',
help = 'check if the given url is valid and exists')
(option, args) = parser.parse_args()
if args:
parser.print_help()
print >> sys.stderr, _('Unexpected arguments!')
sys.exit(1)
return option
def main():
'''
main logic for this tool
read options
get data either through csv file or command line input
generate html file for each event
'''
# parse the option in this argument
opt = parseargs()
eventList = []
# create the output folder if not already exists
if not os.path.exists(opt.output):
os.makedirs(opt.output)
print "Creating the output directory : " + opt.output
else:
print opt.output + " already exists"
# check whether use command line manual input or csv file
if opt.input:
eventList = csvMode(opt)
else:
eventList = manualMode(opt)
print "Creating html files..."
# for each of the event, create a html file and store it to the given location
for e in eventList:
filename = opt.output + '/' + e.name + '.html'
httpTemplate.createHTMLFile(e, filename)
if __name__ == '__main__':
sys.exit(main())