-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup.py
More file actions
79 lines (64 loc) · 2.52 KB
/
startup.py
File metadata and controls
79 lines (64 loc) · 2.52 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
#!/usr/bin/python
class Startup:
"""The startup introduction wizard"""
def __init__(self, client, server):
self.listeners = []
self.server = server
self.client = client
def begin(self):
"""Begins the process of asking questions related\
to how this chat script runs
"""
type = raw_input('Choose the app purpose (server, client): ');
print '-' * 20
if type == 'server':
self.start_server()
elif type == 'client' or type == '':
self.start_client()
else:
self.begin()
def start_server(self):
"""Starts the server startup wizard"""
config = raw_input('Would you like the default config (Y/n): ')
if config == '' or config == 'Y':
print '-' * 20
self.server.start()
self.notify('complete', 'server')
else:
address = raw_input('Server address (localhost):')
port = raw_input('Server port (8000):')
print '-' * 20
self.server.start(address=address or 'localhost', port=port or 8000)
self.notify('complete', 'server')
def start_client(self):
"""Starts the client startup wizard"""
type = raw_input('Is this a sender or receiver window (S/r): ')
full_type = 'receiver' if type == 'r' else 'sender'
handle = raw_input('Please add a user handle (random): ')
if handle != '':
self.client.set_handle(handle)
config = raw_input('Would you like the default config (Y/n): ')
if config == '' or config == 'Y':
print '-' * 20
self.client.connect(type=full_type)
self.notify('complete', full_type)
else:
address = raw_input('Server address (localhost):')
port = raw_input('Server port (8000):')
print '-' * 20
client.connect(address=address or 'localhost', port=port or 8000, type=full_type)
self.notify('complete', full_type)
def addListener(self, listener):
"""Adds listener functions to the listeners list
Keyword arguments:
listener -- a function to add to the list
"""
self.listeners.append(listener)
def notify(self, event, type):
"""Notifies all listeners of an event
Keyword arguments:
event -- the name of an event
type -- the type of instance this window is running
"""
for listener in self.listeners:
listener(event, type)