Ejemplo n.º 1
0
def set_clock_addr(addr):
	addr = format_address(addr)
	print('Setting clock location: {0}'.format(addr))

	for line in fileinput.FileInput(os.path.join(cfg.config_path, 'jsdc.php'), inplace=True):
		line = cfg.replace(line, 'jsdc_clock_address', addr)
		print(line, end='')

	o = urlparse(addr)
	port = o.port if o.port is not None else 80

	inside_node_server = False
	for file in ['config.ts', 'config.js']:
		for line in fileinput.FileInput(os.path.join(cfg.node_path, file), inplace=True):
			try:
				if (inside_node_server):
					if re.match('}', line):
						inside_node_server = False
					elif re.match('^\s*port:', line):
						line = '\tport: %s,\n' % port
				else:
					if re.match('export\s+var\s+nodeServer|exports.nodeServer', line):
						inside_node_server = True
			except Exception as e:
				print(e, sys.stdout)
			finally:
				print(line, end="")
Ejemplo n.º 2
0
def set_server_addr(addr):
	addr = format_address(addr)
	print('Setting server location: {0}'.format(addr))

	for line in fileinput.FileInput(os.path.join(cfg.config_path, 'config.php'), inplace=True):
		line = cfg.replace(line, 'base_url', addr)
		print(line, end='')

	o = urlparse(addr)
	hostname = re.sub(':.+?$', '', o.netloc)
	port = o.port if o.port is not None else 80

	inside_main_server = False
	for file in ['config.js', 'config.ts']:
		for line in fileinput.FileInput(os.path.join(cfg.node_path, file), inplace=True):
			try:
				if (inside_main_server):
					if re.match('}', line):
						inside_main_server = False
					elif re.match('^\s*host:', line):
						line = "\thost: '%s',\n" % hostname
					elif re.match('^\s*port:', line):
						line = '\tport: %s,\n' % port
				else:
					if re.match('export\s+var\s+mainServer|exports.mainServer', line):
						inside_main_server = True
			except Exception as e:
				print(e, file=sys.stdout)
			finally:
				print(line, end='')