def put(local_path, remote_path): """ ..todo:: this should be improved. it may ignore .* file :param local_path: :param remote_path: :return: """ local_path = os.path.expanduser(local_path) if env.host_string: rsync_bin = fabric_local('which rsync', capture=True) rsync = os.path.basename(rsync_bin) if not rsync: raise IOError("rsync not exist.please install it.") tpl = str('%(bin)s -e ssh%(port_str)s%(recursive_str)s ' '%(local_path)s %(host)s:%(remote_path)s') port = int(env.host_string[ env.host_string.find(':') + 1:]) if env.host_string.find( ':') > -1 else 22 host = env.host_string[ 0:env.host_string.find(':')] if env.host_string.find( ':') > -1 else env.host_string port_str = ' %s' % port recursive_str = '' if os.path.isdir(local_path): local_path = local_path.rstrip('/') + '/' remote_path = remote_path.rstrip('/') + '/' recursive_str = ' -r' pass cmd = tpl % { 'bin': rsync, 'local_path': local_path, 'remote_path': remote_path, 'recursive_str': recursive_str, 'port_str': port_str if port != 22 else '', 'host': host } fabric_local(cmd) else: fabric_local("cp -rf %s %s" % (local_path, remote_path)) pass
def update_if_necessary(): with quiet(): latest_version = fabric_local("git tag --sort=v:refname -l \"v*\" | tail -n -1", capture=True) with cd(env.project_path): current_version = run("git describe --tags --always") if latest_version and current_version != latest_version: update(latest_version)
def run(cmd, user=None, capture=None, *args, **kwargs): """ :param cmd: command to execute :param user: user mode will be ignore when we deploy on local machine. :param capture: in local machine, it will be True by default. :param args: :param kwargs: :return: """ if env.hosts: if user: return fabric_run("su - %s -c '%s'" % (user, cmd)) else: return fabric_run(cmd, *args, **kwargs) else: capture = True if capture is None else capture return fabric_local(cmd, capture=capture, *args, **kwargs) pass
def get_repo(): path = os.getcwd() if os.path.exists(os.path.join(path, '.git')): return fabric_local('git remote get-url origin --push', capture=True)