This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
85 lines (82 loc) · 2.65 KB
/
app.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
# Copyright (C) 2011 Alexey Agapitov
# This file is part of Ktope.
#
# Ktope is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
def eulerCycle(g):
st=[]
st.append(0)
res=[]
size=len(g)
while len(st)!=0:
v=st[-1]
i=0
for k in range(size):
if g[v][i]!=0:
break
i+=1
if i==size:
res.append(v+1)
st.pop()
else:
g[v][i]-=1
g[i][v]-=1
st.append(i)
return res
import sys
conf=None
if len(sys.argv)==1:
print('Please specify command to execute')
exit()
if sys.argv[1].startswith('web'):
import cherrypy
import os.path
conf = os.path.join(os.path.dirname(__file__), 'cherrypy.conf')
from ktope.web import hw2,hw3,hw5,main
if sys.argv[1]=='web':
cherrypy.tree.mount(hw2.Hw2Page(), '/hw2', config=conf)
cherrypy.tree.mount(hw3.Hw3Page(), '/hw3', config=conf)
cherrypy.tree.mount(hw5.Hw5Page(), '/hw5', config=conf)
cherrypy.quickstart(main.KtoPage(), config=conf)
elif sys.argv[1]=='web.hw2':
cherrypy.quickstart(hw2.Hw2Page(), '/', config=conf)
elif sys.argv[1]=='web.hw3':
cherrypy.quickstart(hw3.Hw3Page(), '/', config=conf)
elif sys.argv[1]=='web.hw5':
cherrypy.quickstart(hw5.Hw5Page(), '/', config=conf)
elif sys.argv[1]=='cli.hw5':
if len(sys.argv)<2:
print('Please specify a file with circuits')
exit()
from ktope.cli import hw5
hw5.main(sys.argv[2])
elif sys.argv[1]=='euler':
if len(sys.argv)<2:
print('Please specify a file with circuits')
exit()
from ktope import hw2
import fileinput
lines=[]
#only for python >=3.2
'''with fileinput.input(files=(sys.argv[2])) as f:
for line in f:
lines.append(line)
'''
finp=fileinput.input(files=(sys.argv[2]))
for line in finp:
lines.append(line)
finp.close()
circuits=hw2.buildCircuits(lines)
elements=hw2.getElements(circuits)
connMatrix=hw2.buildConnMatrix(circuits,elements)
print(eulerCycle(connMatrix))