本文整理汇总了Python中synctool_lib.stderr函数的典型用法代码示例。如果您正苦于以下问题:Python stderr函数的具体用法?Python stderr怎么用?Python stderr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stderr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: copy_file
def copy_file(self):
self.mkdir_basepath()
src = self.src_path
dest = self.dest_path
if self.dest_isFile():
unix_out('cp %s %s.saved' % (dest, dest))
unix_out('umask 077')
unix_out('cp %s %s' % (src, dest))
if not synctool_lib.DRY_RUN:
old_umask = os.umask(077)
if synctool_param.BACKUP_COPIES:
if self.dest_isFile():
verbose(' saving %s as %s.saved' % (dest, dest))
try:
shutil.copy2(dest, '%s.saved' % dest)
except:
stderr('failed to save %s as %s.saved' % (dest, dest))
verbose(' cp %s %s' % (src, dest))
try:
shutil.copy2(src, dest) # copy file and stats
except:
stderr('failed to copy %s to %s' % (self.print_src(), dest))
os.umask(old_umask)
else:
if self.dest_isFile() and synctool_param.BACKUP_COPIES:
verbose(' saving %s as %s.saved' % (dest, dest))
verbose(dryrun_msg(' cp %s %s' % (src, dest)))
开发者ID:gyepisam,项目名称:synctool,代码行数:35,代码来源:synctool_object.py
示例2: run_remote_copy
def run_remote_copy(nodes, files):
"""copy files[] to nodes[]"""
if not synctool_param.SCP_CMD:
stderr(
"%s: error: scp_cmd has not been defined in %s" % (os.path.basename(sys.argv[0]), synctool_param.CONF_FILE)
)
sys.exit(-1)
scp_cmd_arr = shlex.split(synctool_param.SCP_CMD)
if SCP_OPTIONS:
scp_cmd_arr.extend(shlex.split(SCP_OPTIONS))
for node in nodes:
if node == synctool_param.NODENAME:
verbose("skipping node %s" % node)
nodes.remove(node)
break
scp_cmd_arr.extend(files)
files_str = string.join(files) # this is used only for printing
synctool_lib.run_parallel(master_scp, worker_scp, (nodes, scp_cmd_arr, files_str), len(nodes))
开发者ID:samuelet,项目名称:synctool,代码行数:25,代码来源:synctool_scp.py
示例3: single_files
def single_files(filename):
'''check/update a single file'''
'''returns (True, path_in_synctree) if file is different'''
if not filename:
stderr('missing filename')
return (False, None)
(obj, err) = synctool_overlay.find_terse(synctool_overlay.OV_OVERLAY, filename)
if err == synctool_overlay.OV_FOUND_MULTIPLE:
# multiple source possible
# possibilities have already been printed
sys.exit(1)
if err == synctool_overlay.OV_NOT_FOUND:
stderr('%s is not in the overlay tree' % filename)
return (False, None)
verbose('checking against %s' % obj.print_src())
changed = obj.compare_files()
if not changed:
stdout('%s is up to date' % filename)
terse(synctool_lib.TERSE_OK, filename)
unix_out('# %s is up to date\n' % obj.print_dest())
return (changed, obj.src_path)
开发者ID:gyepisam,项目名称:synctool,代码行数:27,代码来源:synctool.py
示例4: get_latest_version_and_checksum
def get_latest_version_and_checksum():
'''get latest version and checksum by downloading the LATEST.txt versioning file'''
verbose('accessing URL %s' % VERSION_CHECKING_URL)
try:
opener = urllib.FancyURLopener({})
f = opener.open(VERSION_CHECKING_URL)
data = f.read()
f.close()
except:
stderr('error accessing the file at %s' % VERSION_CHECKING_URL)
return None
if data[0] == '<':
stderr('error accessing the file at %s' % VERSION_CHECKING_URL)
return None
data = string.strip(data)
# format of the data in LATEST.txt is:
# <version> <MD5 checksum>
arr = string.split(data)
if len(arr) != 2:
return None
return (arr[0], arr[1])
开发者ID:samuelet,项目名称:synctool,代码行数:27,代码来源:synctool_update.py
示例5: checksum_file
def checksum_file(filename):
'''compute MD5 checksum of a file'''
try:
f = open(filename, 'r')
except IOError, (err, reason):
stderr('error: failed to open %s : %s' % (filename, reason))
raise
开发者ID:samuelet,项目名称:synctool,代码行数:8,代码来源:synctool_update.py
示例6: run_local_synctool
def run_local_synctool():
if not synctool_param.SYNCTOOL_CMD:
stderr('%s: error: synctool_cmd has not been defined in %s' % (os.path.basename(sys.argv[0]),
synctool_param.CONF_FILE))
sys.exit(-1)
cmd_arr = shlex.split(synctool_param.SYNCTOOL_CMD) + PASS_ARGS
synctool_lib.run_with_nodename(cmd_arr, synctool_param.NODENAME)
开发者ID:tevren,项目名称:synctool,代码行数:9,代码来源:synctool_master.py
示例7: ping_nodes
def ping_nodes(nodes):
'''ping nodes in parallel'''
'''nodes is a list of interfaces, really'''
if not synctool_param.PING_CMD:
stderr('%s: error: ping_cmd has not been defined in %s' % (os.path.basename(sys.argv[0]), synctool_param.CONF_FILE))
sys.exit(-1)
synctool_lib.run_parallel(master_ping, worker_ping, nodes, len(nodes))
开发者ID:gyepisam,项目名称:synctool,代码行数:9,代码来源:synctool_ping.py
示例8: hard_delete_file
def hard_delete_file(self):
file = self.dest_path
unix_out('rm -f %s' % file)
if not synctool_lib.DRY_RUN:
verbose(' os.unlink(%s)' % file)
try:
os.unlink(file)
except OSError, reason:
stderr('failed to delete %s : %s' % (file, reason))
开发者ID:gyepisam,项目名称:synctool,代码行数:11,代码来源:synctool_object.py
示例9: set_permissions
def set_permissions(self):
file = self.dest_path
mode = self.src_statbuf.mode
unix_out('chmod 0%o %s' % (mode & 07777, file))
if not synctool_lib.DRY_RUN:
verbose(' os.chmod(%s, %04o)' % (file, mode & 07777))
try:
os.chmod(file, mode & 07777)
except OSError, reason:
stderr('failed to chmod %04o %s : %s' % (mode & 07777, file, reason))
开发者ID:gyepisam,项目名称:synctool,代码行数:12,代码来源:synctool_object.py
示例10: worker_ping
def worker_ping(rank, nodes):
'''ping a single node'''
node = nodes[rank]
nodename = NODESET.get_nodename_from_interface(node)
packets_received = 0
# execute ping command and show output with the nodename
cmd = '%s %s' % (synctool_param.PING_CMD, node)
cmd_arr = shlex.split(cmd)
f = synctool_lib.popen(cmd_arr)
if not f:
stderr('failed to run command %s' % cmd_arr[0])
return
while True:
line = f.readline()
if not line:
break
line = string.strip(line)
#
# argh, we have to parse output here
# ping says something like:
# "2 packets transmitted, 0 packets received, 100.0% packet loss" on BSD
# "2 packets transmitted, 0 received, 100.0% packet loss, time 1001ms" on Linux
#
arr = string.split(line)
if len(arr) > 3 and arr[1] == 'packets' and arr[2] == 'transmitted,':
try:
packets_received = int(arr[3])
except ValueError:
pass
break
# some ping implementations say "hostname is alive" or "hostname is unreachable"
elif len(arr) == 3 and arr[1] == 'is':
if arr[2] == 'alive':
packets_received = 100
elif arr[2] == 'unreachable':
packets_received = -1
f.close()
if packets_received > 0:
print '%s: up' % nodename
else:
print '%s: not responding' % nodename
开发者ID:jumping,项目名称:synctool,代码行数:52,代码来源:synctool_ping.py
示例11: set_owner
def set_owner(self):
file = self.dest_path
uid = self.src_statbuf.uid
gid = self.src_statbuf.gid
unix_out("chown %s.%s %s" % (self.src_ascii_uid(), self.src_ascii_gid(), file))
if not synctool_lib.DRY_RUN:
verbose(" os.chown(%s, %d, %d)" % (file, uid, gid))
try:
os.chown(file, uid, gid)
except OSError, reason:
stderr("failed to chown %s.%s %s : %s" % (self.src_ascii_uid(), self.src_ascii_gid(), file, reason))
开发者ID:samuelet,项目名称:synctool,代码行数:13,代码来源:synctool_object.py
示例12: package_manager
def package_manager():
'''return instance of SyncPkg installer class'''
detected = False
if not synctool_param.PACKAGE_MANAGER:
detect_installer()
if not synctool_param.PACKAGE_MANAGER:
stderr('failed to detect package management system')
stderr('please configure it in synctool.conf')
sys.exit(1)
detected = True
for mgr in synctool_param.KNOWN_PACKAGE_MANAGERS:
if synctool_param.PACKAGE_MANAGER == mgr:
short_mgr = string.replace(mgr, '-', '')
# load the module
module = __import__('synctool_pkg_%s' % short_mgr)
# find the package manager class
pkgclass = getattr(module, 'SyncPkg%s' % string.capitalize(short_mgr))
# instantiate the class
return pkgclass()
if detected:
stderr('package manager %s is not supported yet' % synctool_param.PACKAGE_MANAGER)
else:
stderr("unknown package manager defined: '%s'" % synctool_param.PACKAGE_MANAGER)
sys.exit(1)
开发者ID:gyepisam,项目名称:synctool,代码行数:34,代码来源:synctool_pkg.py
示例13: save_dir
def save_dir(self):
if not synctool_param.BACKUP_COPIES:
return
path = self.dest_path
unix_out('mv %s %s.saved' % (path, path))
if not synctool_lib.DRY_RUN:
verbose('moving %s to %s.saved' % (path, path))
try:
os.rename(path, '%s.saved' % path)
except OSError, reason:
stderr('failed to move directory to %s.saved : %s' % (path, reason))
开发者ID:gyepisam,项目名称:synctool,代码行数:14,代码来源:synctool_object.py
示例14: make_dir
def make_dir(self):
self.mkdir_basepath()
path = self.dest_path
unix_out('umask 077')
unix_out('mkdir %s' % path)
if not synctool_lib.DRY_RUN:
old_umask = os.umask(077)
verbose(' os.mkdir(%s)' % path)
try:
os.mkdir(path)
except OSError, reason:
stderr('failed to make directory %s : %s' % (path, reason))
os.umask(old_umask)
开发者ID:gyepisam,项目名称:synctool,代码行数:18,代码来源:synctool_object.py
示例15: reference
def reference(filename):
'''show which source file in the repository synctool chooses to use'''
if not filename:
stderr('missing filename')
return
(obj, err) = synctool_overlay.find_terse(synctool_overlay.OV_OVERLAY, filename)
if err == synctool_overlay.OV_FOUND_MULTIPLE:
# multiple source possible
# possibilities have already been printed
sys.exit(1)
if err == synctool_overlay.OV_NOT_FOUND:
stderr('%s is not in the overlay tree' % filename)
return
print obj.print_src()
开发者ID:gyepisam,项目名称:synctool,代码行数:18,代码来源:synctool.py
示例16: erase_saved
def erase_saved(self):
dest = self.dest_path
stat_saved_path = synctool_stat.SyncStat('%s.saved' % dest)
if synctool_lib.ERASE_SAVED and stat_saved_path.exists() and not stat_saved_path.isDir():
terse(synctool_lib.TERSE_DELETE, '%s.saved' % dest)
unix_out('rm %s.saved' % dest)
if synctool_lib.DRY_RUN:
stdout(dryrun_msg('erase %s.saved' % dest, 'erase'))
else:
stdout('erase %s.saved' % dest)
verbose(' os.unlink(%s.saved)' % dest)
try:
os.unlink('%s.saved' % dest)
except OSError, reason:
stderr('failed to delete %s : %s' % (dest, reason))
开发者ID:gyepisam,项目名称:synctool,代码行数:18,代码来源:synctool_object.py
示例17: delete_file
def delete_file(self):
file = self.dest_path
if not synctool_lib.DRY_RUN:
if synctool_param.BACKUP_COPIES:
unix_out('mv %s %s.saved' % (file, file))
verbose('moving %s to %s.saved' % (file, file))
try:
os.rename(file, '%s.saved' % file)
except OSError, reason:
stderr('failed to move file to %s.saved : %s' % (file, reason))
else:
unix_out('rm %s' % file)
verbose(' os.unlink(%s)' % file)
try:
os.unlink(file)
except OSError, reason:
stderr('failed to delete %s : %s' % (file, reason))
开发者ID:gyepisam,项目名称:synctool,代码行数:19,代码来源:synctool_object.py
示例18: run_dsh
def run_dsh(remote_cmd_arr):
'''run remote command to a set of nodes using ssh (param ssh_cmd)'''
nodes = NODESET.interfaces()
if nodes == None or len(nodes) <= 0:
print 'no valid nodes specified'
sys.exit(1)
if not synctool_param.SSH_CMD:
stderr('%s: error: ssh_cmd has not been defined in %s' % (os.path.basename(sys.argv[0]), synctool_param.CONF_FILE))
sys.exit(-1)
ssh_cmd_arr = shlex.split(synctool_param.SSH_CMD)
if SSH_OPTIONS:
ssh_cmd_arr.extend(shlex.split(SSH_OPTIONS))
synctool_lib.run_parallel(master_ssh, worker_ssh,
(nodes, ssh_cmd_arr, remote_cmd_arr), len(nodes))
开发者ID:gyepisam,项目名称:synctool,代码行数:19,代码来源:synctool_ssh.py
示例19: run_remote_pkg
def run_remote_pkg(nodes):
if not nodes:
return
if not synctool_param.SSH_CMD:
stderr('%s: error: ssh_cmd has not been defined in %s' % (os.path.basename(sys.argv[0]), synctool_param.CONF_FILE))
sys.exit(-1)
if not synctool_param.PKG_CMD:
stderr('%s: error: pkg_cmd has not been defined in %s' % (os.path.basename(sys.argv[0]), synctool_param.CONF_FILE))
sys.exit(-1)
# prepare remote synctool_pkg command
ssh_cmd_arr = shlex.split(synctool_param.SSH_CMD)
pkg_cmd_arr = shlex.split(synctool_param.PKG_CMD)
pkg_cmd_arr.extend(PASS_ARGS)
# run in parallel
synctool_lib.run_parallel(master_pkg, worker_pkg,
(nodes, ssh_cmd_arr, pkg_cmd_arr), len(nodes))
开发者ID:samuelet,项目名称:synctool,代码行数:20,代码来源:synctool_master_pkg.py
示例20: download
def download():
'''download latest version'''
# ugly globals because of callback function
global DOWNLOAD_FILENAME, DOWNLOAD_BYTES
tup = get_latest_version_and_checksum()
if not tup:
return 1
(version, checksum) = tup
filename = 'synctool-%s.tar.gz' % version
download_url = DOWNLOAD_URL + filename
DOWNLOAD_FILENAME = make_local_filename_for_version(version)
DOWNLOAD_BYTES = 0
try:
opener = urllib.FancyURLopener({})
opener.retrieve(download_url, DOWNLOAD_FILENAME, download_progress)
except:
if DOWNLOAD_BYTES:
print
stderr('failed to download file %s' % download_url)
return 1
else:
print
#
# compute and compare MD5 checksums
# sadly, there is no easy way to do this 'live' while downloading,
# because the download callback does not see the downloaded data blocks
#
downloaded_sum = checksum_file(DOWNLOAD_FILENAME)
if downloaded_sum != checksum:
stderr('ERROR: checksum failed for %s' % DOWNLOAD_FILENAME)
return 1
return 0
开发者ID:samuelet,项目名称:synctool,代码行数:41,代码来源:synctool_update.py
注:本文中的synctool_lib.stderr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论