当前位置: 首页>>代码示例>>Python>>正文


Python synctool_lib.stderr函数代码示例

本文整理汇总了Python中synctool_lib.stderr函数的典型用法代码示例。如果您正苦于以下问题:Python stderr函数的具体用法?Python stderr怎么用?Python stderr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了stderr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的synctool_lib.stderr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。