Commit c2a99c9e authored by Jondy Zhao's avatar Jondy Zhao

Add support for cygwin.

parent 5098f660
...@@ -523,10 +523,11 @@ class User(object): ...@@ -523,10 +523,11 @@ class User(object):
# XXX: This method shall be no-op in case if all is correctly setup # XXX: This method shall be no-op in case if all is correctly setup
# This method shall check if all is correctly done # This method shall check if all is correctly done
# This method shall not reset groups, just add them # This method shall not reset groups, just add them
grpname = 'grp_' + self.name if sys.platform == 'cygwin' else self.name
try: try:
grp.getgrnam(self.name) grp.getgrnam(grpname)
except KeyError: except KeyError:
callAndRead(['groupadd', self.name]) callAndRead(['groupadd', grpname])
user_parameter_list = ['-d', self.path, '-g', self.name, '-s', user_parameter_list = ['-d', self.path, '-g', self.name, '-s',
'/bin/false'] '/bin/false']
...@@ -697,6 +698,9 @@ class Interface(object): ...@@ -697,6 +698,9 @@ class Interface(object):
except KeyError: except KeyError:
raise ValueError("%s must have at least one IPv6 address assigned" % \ raise ValueError("%s must have at least one IPv6 address assigned" % \
interface_name) interface_name)
if sys.platform == 'cygwin':
for q in address_list:
q.setdefault('netmask', 'FFFF:FFFF:FFFF:FFFF::')
# XXX: Missing implementation of Unique Local IPv6 Unicast Addresses as # XXX: Missing implementation of Unique Local IPv6 Unicast Addresses as
# defined in http://www.rfc-editor.org/rfc/rfc4193.txt # defined in http://www.rfc-editor.org/rfc/rfc4193.txt
# XXX: XXX: XXX: IT IS DISALLOWED TO IMPLEMENT link-local addresses as # XXX: XXX: XXX: IT IS DISALLOWED TO IMPLEMENT link-local addresses as
...@@ -811,7 +815,8 @@ class Interface(object): ...@@ -811,7 +815,8 @@ class Interface(object):
def addIPv4LocalAddress(self, addr=None): def addIPv4LocalAddress(self, addr=None):
"""Adds local IPv4 address in ipv4_local_network""" """Adds local IPv4 address in ipv4_local_network"""
netmask = '255.255.255.255' netmask = '255.255.255.254' if sys.platform == 'cygwin' \
else '255.255.255.255'
local_address_list = self.getIPv4LocalAddressList() local_address_list = self.getIPv4LocalAddressList()
if addr is None: if addr is None:
return self._generateRandomIPv4Address(netmask) return self._generateRandomIPv4Address(netmask)
...@@ -1140,7 +1145,7 @@ class Config(object): ...@@ -1140,7 +1145,7 @@ class Config(object):
except ValueError: except ValueError:
pass pass
except OSError: except OSError:
missing_binary_list.append(b) missing_binary_list.append(b[0])
if missing_binary_list: if missing_binary_list:
raise UsageError('Some required binaries are missing or not ' raise UsageError('Some required binaries are missing or not '
'functional: %s' % (','.join(missing_binary_list), )) 'functional: %s' % (','.join(missing_binary_list), ))
...@@ -1326,6 +1331,14 @@ def tracing_monkeypatch(config): ...@@ -1326,6 +1331,14 @@ def tracing_monkeypatch(config):
def main(*args): def main(*args):
"Run default configuration." "Run default configuration."
if sys.platform in ('cygwin',):
callAndRead = lambda args, flag=True : args.insert(0, '/bin/sh') \
or real_callAndRead(args, flag)
f = netifaces.ifaddresses
netifaces.ifaddresses = lambda s,f=f:reduce( \
lambda x,y:[x.__setitem__(k,v + x.get(k,[])) for k,v in y.iteritems()] and x, \
filter(None, [f(i) for i in netifaces.interfaces() if i.startswith(s)]),{})
# Parse arguments # Parse arguments
usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0] usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
options, configuration_file_path = Parser(usage=usage).check_args(args) options, configuration_file_path = Parser(usage=usage).check_args(args)
......
...@@ -679,7 +679,7 @@ class Slapgrid(object): ...@@ -679,7 +679,7 @@ class Slapgrid(object):
process_handler = subprocess.Popen(command, process_handler = subprocess.Popen(command,
preexec_fn=lambda: dropPrivileges(uid, gid), preexec_fn=lambda: dropPrivileges(uid, gid),
cwd=cwd, cwd=cwd,
env={}, **kw) env=None if sys.platform == 'cygwin' else {}, **kw)
process_handler.stdin.flush() process_handler.stdin.flush()
process_handler.stdin.close() process_handler.stdin.close()
process_handler.stdin = None process_handler.stdin = None
......
...@@ -95,6 +95,8 @@ class SlapPopen(subprocess.Popen): ...@@ -95,6 +95,8 @@ class SlapPopen(subprocess.Popen):
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs.update(stdin=subprocess.PIPE) kwargs.update(stdin=subprocess.PIPE)
if sys.platform == 'cygwin' and kwargs.get('env') == {}:
kwargs['env'] = None
subprocess.Popen.__init__(self, *args, **kwargs) subprocess.Popen.__init__(self, *args, **kwargs)
self.stdin.flush() self.stdin.flush()
self.stdin.close() self.stdin.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment