-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
141 lines (126 loc) · 4.23 KB
/
client.py
File metadata and controls
141 lines (126 loc) · 4.23 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
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
import logging, os, json, time, copy, time, datetime, re, urllib, urllib2, httplib, sys
from base64 import b64encode, b64decode
from uuid import uuid4
from yadapy.lib.crypt import encrypt, decrypt
from yadapy.sqlite.nodesqlite import *
from yadapy.manager import YadaServer
from yadapy.nodecommunicator import NodeCommunicator
def getTerminalSize():
import os
env = os.environ
def ioctl_GWINSZ(fd):
try:
import fcntl, termios, struct, os
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
'1234'))
except:
return None
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
try:
cr = (env['LINES'], env['COLUMNS'])
except:
cr = (25, 80)
return int(cr[1]), int(cr[0])
node = False
nodeClient = False
logo = """
%s
yyyyyyy yyyyyy aaaaaa ddddddddddddd aaaaaa
yyyyyy yyyyy aaaaaaa dddddddddddddddd aaaaaaa
yyyy yyyyy aaaaaaaaa dddddd dddd aaaaaaaaa
yyy yyyyy aaaaa aaaa dddddd ddddd aaaaa aaaa
yyyy yyyy aaaaa aaaa dddddd ddddd aaaaa aaaa
yyyyyy aaaaaaaaaaaaaaa dddddd ddddd aaaaaaaaaaaaaaa
yyyy aaaaaaaaaaaaaaaa dddddd ddddddd aaaaaaaaaaaaaaaa
yyyy aaaaaaa aaaaa ddddddddddddddd aaaaaaa aaaaa
yyyy aaaaaaa aaaaaaa ddddddddddddd aaaaaaa aaaaaaa
______ ______ ______ __ ______ ______ ______
/\ == \ /\ == \ /\ __ \ /\ \ /\ ___\ /\ ___\ /\__ _\
\ \ _-/ \ \ __< \ \ \/\ \ _\_\ \ \ \ __\ \ \ \____ \/_/\ \/
\ \_\ \ \_\ \_\ \ \_____\ /\_____\ \ \_____\ \ \_____\ \ \_\
\/_/ \/_/ /_/ \/_____/ \/_____/ \/_____/ \/_____/ \/_/
%s
""" % (("\n" * (getTerminalSize()[1])), ("\n" * (getTerminalSize()[1])))
def frame(text):
textLen = len(text)
frameTopBottom = "*" * (textLen + 14)
frameStr = """
%s
* %s *
%s
""" % (frameTopBottom, text, frameTopBottom)
return frameStr
if __name__ == '__main__':
clear = lambda: os.system('cls')
#screen 1
raw_input("""
%s
%s
[Press Enter]""" % (logo, frame("Welcome to your new Social Network!")))
clear()
#screen 2
while 1:
var = raw_input("""
%s
%s
Enter the host name and port ie.localhost:80: """ % (logo, frame("Lets check that your server is up.")))
try:
varSplit = var.split(":")
host = varSplit[0]
port = varSplit[1]
except:
raw_input("ERROR: You did not enter a valid host name and port number. Format: localhost:80 [Press Enter]")
clear()
continue
try:
res = urllib2.urlopen('http://%s/' % var)
data = res.read()
res.close()
break
except:
raw_input("ERROR: Host is inaccessible [Press Enter]")
clear()
continue
#screen 3
while 1:
var = raw_input("""
%s
%s
Type the absolute path to your sqlite database file: """ % (logo, frame("Good, your server responded.")))
try:
node = Node({}, {"name" : "NodeServer"}, location=var)
nodeClient = NodeCommunicator(node)
break
except:
raw_input("ERROR: This is not a valid path to an sqlite database file [Press Enter]")
clear()
continue
#screen 4
try:
# Win32
from msvcrt import getch
except ImportError:
# UNIX
def getch():
import sys, tty, termios
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
try:
tty.setraw(fd)
return sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
while 1:
var = getch()
print var
clear()
continue