Пример #1
0
#!/usr/bin/python

import os, shutil, parse, safe, apachehost
from random import Random

parse.parser.usage = '%prog HOST'
bitrix_file = 'templates/bitrix8setup.php'
parse.shovel({'name': 'installer', 'help': 'Path to bitrix installer script', 'short': 'd', 'default': os.path.join(os.path.dirname(os.path.realpath(__file__)), bitrix_file)})

if __name__ == '__main__':
	if len(parse.arguments) < 1:
		safe.quit('Please, provide host name\n' + parse.parser.format_help(), 1)
	
	# find apache host and get it's document root
	try:
		host = apachehost.find(apachehost.config_dir(), parse.arguments[0]).next() # we need only the first [0] host, since it has precedence in apache
	except StopIteration:
		safe.quit('Can\'t find host named {0}'.format(parse.arguments[0]), 1)
	
	newname = '{0}.php'.format(Random().randint(10**6, 10**7-1))
	
	docroot = os.path.join(os.path.normpath(apachehost.get(host, 'DocumentRoot')['DocumentRoot']), newname)
	
	# copy bitrix8setup.php to a randomly named php file
	safe.catch(shutil.copy, (parse.options['installer'], docroot), 'Can\'t copy bitrix installer to {1}.')
	
	# run default web browser
	os.system('x-www-browser http://{0}/{1}'.format(parse.arguments[0], newname))
	
	safe.quit('Success! Do installation instructions in your browser.')
Пример #2
0
#!/usr/bin/python

import os, parse, safe, apachehost

parse.parser.usage = '%prog SERVERNAME [options]'
parse.shovel({'name': 'docroot', 'help': 'Server\'s document root. Default: /var/www/SERVERNAME/public_html', 'short': 'd', 'default': '/var/www/{0}/public_html/'},\
{'name': 'admin', 'help': 'Admin\'s contact email', 'default': 'webmaster@localhost', 'short': 'a'},\
{'name': 'override_docroot', 'help': 'AllowOverride for DocumentRoot', 'default': 'All'},\
{'name': 'override_cgi', 'help': 'AllowOverride for cgi-bin', 'default': 'All'},\
{'name': 'host_template', 'help': 'Template for host configuration (./config.template by default)', 'default': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates', 'config.template')})


if __name__ == '__main__':
	if len(parse.arguments) < 1: # 1 argument (server name) is required
		safe.quit(parse.parser.format_help())
	
	apachehost.create(parse.options, parse.arguments)
Пример #3
0
#!/usr/bin/python

import os, shutil, parse, safe, apachehost
from random import Random

tpl_suffix = '.nano.php'
default_title = 'Page title'

if __name__ == '__main__':
	parse.parser.usage = '%prog TEMPLATE [DEST]'
	parse.shovel({'name': 'force', 'help': 'Overwrite DEST if exists.', 'short': 'f', 'default': False}, {'name': 'title', 'help': 'Set page title', 'short': 't', 'default': default_title})
	
	if len(parse.arguments) < 2:
		safe.quit('Please, provide host name, template name and destination filename.\n' + parse.parser.format_help(), 1)
	
	# check if template exists
	src = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates', parse.arguments[1] + tpl_suffix)
	
	if not os.path.isfile(src):
		safe.quit('There is no template {0} in templates folder ({1})'.format(parse.arguments[1], src), 1)
	
	# compose destination path
	dest = os.getcwd()
	if len(parse.arguments) > 1:
		dest = os.path.join(dest, parse.arguments[2])
	
	if os.path.isdir(dest):
		dest = os.path.join(dest, parse.arguments[1].replace(tpl_suffix, '.php'))
	
	if dest[-4:] != '.php':
		dest += '.php'
Пример #4
0
	'DVD-DL': 4.7e+9 * 2,
	'CD': 7.0e+8,
	'BR': 2.2e+10,
	'test': 1e+8
}

disk_overhead = 0.05
graft_name = 'graft-disk-{0}.txt'

def padn(n, b = 2048):
	return n - (n % b) + b if n % b > 0 else n

if __name__ == '__main__':
	comlpetePath = lambda path: os.path.join(parse.options['output'], path)
	
	parse.shovel(parse_params)
	
	dirs = [[], []]
	for i in parse.arguments:
		dirs[os.path.isdir(i)].append(i)
	
	if len(dirs[0]) > 0:
		print 'The following paths aren\'t directories and were ignored:\n' + '\n'.join(non_dirs)
	
	dates = {}
	for i in ['from', 'to']:
		match = re.search(r'^(\d{4})-(\d\d)-(\d\d)$', str(parse.options.get(i, '')))
		if match is not None:
			dates[i] = match.groups(0)

	def removeAncestors(dirs):