示例#1
0
def __read(path, func):
	try:
		lines = cat(path)
		func("echo 'log lines         : %s'; echo '%s'" % (path, lines))

	except AssertionError as e:
		error("echo 'no such file : %s'" % path)
示例#2
0
def echo_to_spool(user, line):
    path = '%s/%s' % (spool, user)
    if isExistsLine(path, line):
        error('echo already exists : %s in %s' % (line, path))
    else:
        execute("echo '%s' >> %s" % (line, path))
        __chown(user, path)
        done("echo -n 'create shell : '; ls -l %s" % path)
示例#3
0
def sed(path, src, dst, e = False):
	if not isExists(path):
		error('echo not exists : %s' % path)
		return

	option = ['-i', '-ie'][e]

	execute("sed %s 's/%s/%s/' %s" % (option, __escape(src), __escape(dst), path))
示例#4
0
def sed(path, src, dst, e=False):
    if not isExists(path):
        error('echo not exists : %s' % path)
        return

    option = ['-i', '-ie'][e]

    execute("sed %s 's/%s/%s/' %s" %
            (option, __escape(src), __escape(dst), path))
示例#5
0
def __install(package, repositories):
	if __isNotInstalled(package):
		with hide('stdout'):
			stdout = execute('yum install -y %s%s; true' % (__enablerepos(repositories), package))
			if 'Error: Nothing to do' in stdout:
				error("echo 'install error     : No package %s available.'" % package)
			else:
				done("echo 'install complete  : %s'" % __version(package))
	else:
		already("echo 'already installed : %s'" % __version(package))
示例#6
0
def put_to_directory(user, directory, shell, sudo=False):
    path = '%s/%s' % (directory, os.path.basename(shell))

    if isExists(path):
        error('echo already exists : %s' % path)
    else:
        put(shell, directory, use_sudo=sudo)
        __chmod(path)
        __chown(user, path)
        done("echo -n 'send shell   : '; ls -l %s" % path)
示例#7
0
def __start(service):
	if __isRunning(service):
		already("echo 'already started : %s'" % service)
	else:
		with hide('everything'):
			stdout = execute('service %s start; true' % service)
			if 'unrecognized' in stdout:
				error("echo 'start error     : %s is unrecognized'" % service)
			else:
				done("echo 'started         : %s'" % service)
示例#8
0
def __on(service):
	if __isOn(service):
		already("echo 'already on      : %s'" % service)
	else:
		with hide('everything'):
			stdout = execute('chkconfig %s on; true' % service)
			if 'No such file or directory' in stdout:
				error("echo 'turn on error   : %s is unrecognized'" % service)
			else:
				done("echo 'turn on         : %s'" % service)
示例#9
0
def echo_to_directory(user, directory, shell_line, shell_name):
    path = '%s/%s' % (directory, shell_name)

    if isExists(path):
        error('echo already exists : %s' % path)
    else:
        execute("echo '%s' > %s" % (shell_line, path))
        __chmod(path)
        __chown(user, path)
        done("echo -n 'create shell : '; ls -l %s" % path)
示例#10
0
def __install(package, repositories):
    if __isNotInstalled(package):
        with hide('stdout'):
            stdout = execute('yum install -y %s%s; true' %
                             (__enablerepos(repositories), package))
            if 'Error: Nothing to do' in stdout:
                error("echo 'install error     : No package %s available.'" %
                      package)
            else:
                done("echo 'install complete  : %s'" % __version(package))
    else:
        already("echo 'already installed : %s'" % __version(package))
示例#11
0
def __backup(path):
	if __hasNoBackup(path):
		if not isExists(path):
			error('echo not exists : %s' % path)
			return False
		else:
			with hide('everything'):
				execute('cp -p %s %s.origin' % (path, path))
			done('echo create backup : %s.origin' % path)
			return True
	else:
		already('echo already exists : %s' % path)
		return True
示例#12
0
def __backup(path):
    if __hasNoBackup(path):
        if not isExists(path):
            error('echo not exists : %s' % path)
            return False
        else:
            with hide('everything'):
                execute('cp -p %s %s.origin' % (path, path))
            done('echo create backup : %s.origin' % path)
            return True
    else:
        already('echo already exists : %s' % path)
        return True
示例#13
0
def clone(repository, dst, branch = 'master'):
	if isExists(dst):
		error('echo already exists : %s' % dst)
	else:
		with hide('stdout'):
			stdout = execute('git clone -b %s %s %s; true' % (branch, repository, dst))
			if '403 Forbidden' in stdout:
				error("echo -n 'clone error    : 403 Forbidden'")
			else:
				if 'warning: Remote branch %s not found' % branch in stdout:
					error("echo -n 'warning        : %s dones not found'" % branch)
				done("echo -n 'complete clone : '; ls -ld %s" % dst)
				done("echo -n 'branch         : '; cd %s; git rev-parse --abbrev-ref HEAD" % dst)
示例#14
0
def clone(repository, dst, branch='master'):
    if isExists(dst):
        error('echo already exists : %s' % dst)
    else:
        with hide('stdout'):
            stdout = execute('git clone -b %s %s %s; true' %
                             (branch, repository, dst))
            if '403 Forbidden' in stdout:
                error("echo -n 'clone error    : 403 Forbidden'")
            else:
                if 'warning: Remote branch %s not found' % branch in stdout:
                    error("echo -n 'warning        : %s dones not found'" %
                          branch)
                done("echo -n 'complete clone : '; ls -ld %s" % dst)
                done(
                    "echo -n 'branch         : '; cd %s; git rev-parse --abbrev-ref HEAD"
                    % dst)
示例#15
0
def link(origin, link):
	if not isExists(origin):
		error('echo not exists : %s' % origin)
	else:
		execute('ln --symbolic --force %s %s' % (origin, link))
		done("echo -n 'link   : '; ls -l %s" % link)
示例#16
0
def __reload(service):
	stdout = execute('service %s reload; true' % service)
	if 'unrecognized' in stdout:
		error("echo 'reload error : %s is unrecognized'" % service)
示例#17
0
def link(origin, link):
    if not isExists(origin):
        error('echo not exists : %s' % origin)
    else:
        execute('ln --symbolic --force %s %s' % (origin, link))
        done("echo -n 'link   : '; ls -l %s" % link)