def __stop(service): if __isRunning(service): with hide('everything'): execute('service %s stop' % service) done("echo 'stopped : %s'" % service) else: already("echo 'already stopped : %s'" % service)
def __off(service): if __isOn(service): with hide('everything'): execute('chkconfig %s off' % service) done("echo 'turn off : %s'" % service) else: already("echo 'already off : %s'" % service)
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)
def __addRepository(name, url): package = __repository(name) if __doesNotHasRepository(package): with hide('everything'): execute('rpm -iv %s' % url) done("echo 'install complete : %s'" % __repository(name)) else: already("echo 'already installed : %s'" % package)
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))
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)
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)
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)
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)
def generate(): from result import done, already dst = '%s/my_configure.py' % os.getcwd() src = os.path.join(os.path.dirname(__file__), 'default_configure.py') if os.path.exists(dst): already('echo already exists : %s' % dst) else: with hide('everything'): local('cp %s %s' % (src, dst)) done('echo cteate complete : %s' % dst)
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
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)
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)
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)
def __diff(path): done("echo 'diff'; diff %s %s.origin; true" % (path, path))
def update(): with hide('stdout'): execute('yum update -y') done('echo complete : yum update')