segfaulthunter / pypentago-mainline
pypentago is an open source effort to recreate the board-game Pentago using Python.
Clone this repository (size: 1.1 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/segfaulthunter/pypentago-mainline/
| commit 411: | 7b7bc4f7a28a |
| parent 410: | 3777000c14e4 |
| branch: | default |
Put servers into client.ini.
Changed (Δ2.7 KB):
raw changeset »
src/pypentago/client/interface/__init__.py (2 lines added, 1 lines removed)
src/pypentago/client/main.py (12 lines added, 1 lines removed)
src/pypentago/conf.py (53 lines added, 0 lines removed)
src/pypentago/util.py (25 lines added, 0 lines removed)
Up to file-list src/pypentago/client/interface/__init__.py:
| … | … | @@ -100,7 +100,8 @@ def main(default_servers=[]): |
100 |
100 |
main = MainWindow() |
101 |
101 |
main.show() |
102 |
102 |
for server in default_servers: |
103 |
g = ServerWindow.from_string(server |
|
103 |
g = ServerWindow.from_string(server.address, server.user, |
|
104 |
server.password) |
|
104 |
105 |
g.show() |
105 |
106 |
main.windows.append(g) |
106 |
107 |
reactor.run() |
Up to file-list src/pypentago/client/main.py:
| … | … | @@ -31,6 +31,7 @@ from ConfigParser import ConfigParser |
31 |
31 |
import pypentago |
32 |
32 |
|
33 |
33 |
from pypentago import conf |
34 |
from pypentago import util |
|
34 |
35 |
from pypentago.client import interface |
35 |
36 |
from pypentago import __version__, verbosity_levels |
36 |
37 |
|
| … | … | @@ -74,9 +75,19 @@ def main(args=None): |
74 |
75 |
|
75 |
76 |
logfile = config.get("client", "logfile", vars=var) |
76 |
77 |
|
78 |
servers = conf.parse_servers(config) |
|
79 |
connect = [] |
|
80 |
for arg in args: |
|
81 |
if arg in servers: |
|
82 |
connect.append(servers[arg]) |
|
83 |
else: |
|
84 |
connect.append(util.parse_connect(arg)) |
|
85 |
connect.extend(server for server in servers.itervalues() |
|
86 |
if server.autoconnect) |
|
87 |
||
77 |
88 |
pypentago.init_logging(logfile, verbosity) |
78 |
89 |
log = logging.getLogger("pypentago.client") |
79 |
interface.main( |
|
90 |
interface.main(connect) |
|
80 |
91 |
|
81 |
92 |
|
82 |
93 |
if __name__ == "__main__": |
Up to file-list src/pypentago/conf.py:
| … | … | @@ -23,6 +23,7 @@ from __future__ import with_statement |
23 |
23 |
|
24 |
24 |
import os |
25 |
25 |
import pypentago |
26 |
from pypentago import util |
|
26 |
27 |
|
27 |
28 |
from ConfigParser import RawConfigParser |
28 |
29 |
|
| … | … | @@ -89,6 +90,10 @@ def init_client_conf(location): |
89 |
90 |
client.add_section('client') |
90 |
91 |
client.set('client', 'logfile', '%(appdata)s/client.log') |
91 |
92 |
|
93 |
client.add_section('servers') |
|
94 |
client.set('servers', 'all', '') |
|
95 |
client.set('servers', 'autoconnect', '') |
|
96 |
||
92 |
97 |
with open(client_file, 'w') as client_file: |
93 |
98 |
client.write(client_file) |
94 |
99 |
|
| … | … | @@ -111,3 +116,51 @@ def possible_configs(file_name, location |
111 |
116 |
if os.path.exists(name): |
112 |
117 |
yield os.path.abspath(name) |
113 |
118 |
|
119 |
||
120 |
def parse_servers(parser): |
|
121 |
ret = {} |
|
122 |
if (not parser.has_section('servers') or |
|
123 |
not parser.has_option('servers', 'all')): |
|
124 |
return {} |
|
125 |
||
126 |
servers = parser.get('servers', 'all') |
|
127 |
server_list = [s.strip() for s in servers.split(',')] |
|
128 |
if parser.has_option('servers', 'autoconnect'): |
|
129 |
auto = parser.get('servers', 'autoconnect') |
|
130 |
auto_list = [s.strip() for s in auto.split(',')] |
|
131 |
else: |
|
132 |
auto_list = [] |
|
133 |
||
134 |
for server in server_list: |
|
135 |
if parser.has_option(server, 'address'): |
|
136 |
address = parser.get(server, 'address') |
|
137 |
else: |
|
138 |
continue |
|
139 |
||
140 |
if parser.has_option(server, 'name'): |
|
141 |
name = parser.get(server, 'name') |
|
142 |
else: |
|
143 |
# Better than nothing. |
|
144 |
name = server |
|
145 |
||
146 |
if parser.has_option(server, 'description'): |
|
147 |
description = parser.get(server, 'description') |
|
148 |
else: |
|
149 |
description = None |
|
150 |
||
151 |
if parser.has_option(server, 'user'): |
|
152 |
user = parser.get(server, 'user') |
|
153 |
else: |
|
154 |
user = None |
|
155 |
||
156 |
if parser.has_option(server, 'password'): |
|
157 |
password = parser.get(server, 'password') |
|
158 |
else: |
|
159 |
password = None |
|
160 |
||
161 |
autoconnect = server in auto_list |
|
162 |
ret[server] = util.ServerInfo( |
|
163 |
address=address, name=name, description=description, |
|
164 |
user=user, password=password, autoconnect=autoconnect |
|
165 |
) |
|
166 |
return ret |
Up to file-list src/pypentago/util.py:
| … | … | @@ -64,6 +64,17 @@ class IDPool(object): |
64 |
64 |
self.free_ids = [] |
65 |
65 |
|
66 |
66 |
|
67 |
class ServerInfo(object): |
|
68 |
def __init__(self, address, name=None, description=None, |
|
69 |
user=None, password=None, autoconnect=False): |
|
70 |
self.address = address |
|
71 |
self.name = name |
|
72 |
self.description = description |
|
73 |
self.user = user |
|
74 |
self.password = password |
|
75 |
self.autoconnect = autoconnect |
|
76 |
||
77 |
||
67 |
78 |
def parse_ipv4(string, default_port=-1): |
68 |
79 |
h = string.split(':') |
69 |
80 |
if len(h) == 1: |
| … | … | @@ -122,3 +133,17 @@ def contains(row, col): |
122 |
133 |
if col > 2: |
123 |
134 |
r += 1 |
124 |
135 |
return r |
136 |
||
137 |
def parse_connect(string): |
|
138 |
if '@' in string: |
|
139 |
auth, address = string.split('@', 1) |
|
140 |
if ':' in auth: |
|
141 |
user, passwd = auth.split(':', 1) |
|
142 |
else: |
|
143 |
user = auth |
|
144 |
password = None |
|
145 |
else: |
|
146 |
user = None |
|
147 |
password = None |
|
148 |
address = string |
|
149 |
return ServerInfo(address=address, user=user, password=password) |
