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


Python Validator.validate_non_empty_string方法代码示例

本文整理汇总了Python中thedeployer.packages.depfile.validator.Validator.validate_non_empty_string方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.validate_non_empty_string方法的具体用法?Python Validator.validate_non_empty_string怎么用?Python Validator.validate_non_empty_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thedeployer.packages.depfile.validator.Validator的用法示例。


在下文中一共展示了Validator.validate_non_empty_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: put

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def put(self, source, destination, excludes = None, contents_only = False, recursive = False, create_dirs = False, replace = False, filter_chain = None, retry = 1):
		'''
		upload file or folder from the source into the destination
		
		@param source: local path
		@param destination: destination path
		@param excludes: list of excluded files or folders from the uploading operation 
		@param recusive: boolean for upload the folder with its subfolders or not
		@param contents_only: boolean for uploading the contents of the dir directly to the server without creating it on the server
								or create it first and upload the data inside it  
		@param create_dirs: boolean for creating the destination if not exist or not
		@param replace: replace the existing files or not
		@param filter_chain: filter for the uploaded files
		@param retry: if file uploading failed try again with number of retry 
		
		@raise InvalidParameterError: if parameters are not valid
		@raise FileNotExistsError: if source file or directory is not exist or if create_dirs equal False and destination directory is not exist
		@raise FileExistsError: if destination already exists and and replace is false
		@raise FilePutError: if error occurred during copying
		'''
		if not Validator.validate_non_empty_string(source):
			raise InvalidParameterError("source", "source can not be None or empty string")

		if not Validator.validate_non_empty_string(destination):
			raise InvalidParameterError("destination", "destination can not be None")

		#if the client is None
		if self.__ftp_client is None:			
			self.connect()
		
		source = source.rstrip(' ')
		source = source.rstrip(os.sep)

		if destination == '.':
			destination = self.get_cwd()
		else:
			destination = self.append_to_root(destination)

		if not os.path.exists(source):
			raise FileNotExistsError, source

		if not self.is_exists(destination):
			if create_dirs:
				self.mkdir(destination, recursive = True)
			else:
				raise FileNotExistsError, destination
		else:
			if self.get_type(destination) == FileObject.FILE:
				raise FileExistsError, destination

		newdestination = self.get_platform().join(destination, os.path.basename(source))
		if self.is_exists(newdestination):
			 if not replace:
					raise FileExistsError, newdestination
		
		if os.path.isfile(source):
			try:
				self.__put(source, destination, excludes, replace, recursive, filter_chain, retry)
			except Exception, e:
				raise FilePutError('can not upload ' + source, str(e))
开发者ID:vimov,项目名称:Deployer,代码行数:62,代码来源:ftpbase.py

示例2: __init__

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def __init__(self, platform, host, port = 22, username = "", password = "", certificate_file = "", passphrase = "", root = ""):
		"""
		Constructor for the class.

		@param id: The identifier of this server, must be a non-empty string.
		@param host: The host of the Rsync server.
		@param port: The port of the server.
		@param username: Username.
		@param password: Password.
		@param certificate_file: Path to a local certificate file.
		@param passphrase: The passphrase encrypting the certificate file.
		"""

		if not Validator.validate_non_empty_string(host):
			raise InvalidParameterError('host', 'host can not be None or empty string')
		
		if not Validator.validate_integer(port):
			raise InvalidParameterError('port', 'port must be integer')

		if not Validator.validate_non_empty_string(certificate_file) and ( not Validator.validate_non_empty_string(username) or not Validator.validate_non_empty_string(password)):
			raise InvalidParameterError('username', 'A username and password must be specified if not using certificate login')

		self.__certificate_file = certificate_file
		self.__passphrase = passphrase
		
		super(SshClient, self). __init__(platform, host, username, password, port, root)
		self.connect()
开发者ID:vimov,项目名称:Deployer,代码行数:29,代码来源:sshclient.py

示例3: mkdir

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def mkdir(self, path, mode = "755", recursive = False, retry = 1):
		'''
		make a directory on the remote server on the current directory, if the parameter is path 
		it must be found except the basename 
		Example:
		dir = a/b/c
		a/b must be found and c will be created
		 if dir = a then a will be created 
		
		@param path: directory path
		@param mode: mode of the directory
		@param recurisve : boolean for creating the full path or the last level only
		@param retry: count of the function retry 

		@raise InvalidParameterError: If the required argument(s) are not specified.
		  		
		@raise MakeDirError: If the function failed to make the directory
		'''

		if not Validator.validate_non_empty_string(path):
			raise InvalidParameterError("path", "path can not be None or empty string")
		
		if not Validator.validate_non_empty_string(mode):
			raise InvalidParameterError("mode", "mode can not be None or empty string")
		
		try:
			mode = self.__get_permissions(mode)
			path = self.append_to_root(path)
			if not recursive:
					if self.is_exists(path):
						if  self.get_type(path) == FileObject.FILE:
							raise FileExistsError("can not replace file with directory " + path)
					else:
						self.__mkdir(path, mode, retry)
			else:
				base =  self.get_root()
				tmp = path[len(base):] 
				list = tmp.split(self.get_platform().get_separator())
				for dir in list:
					if len(dir) > 0:
						base = base + dir
						if self.is_exists(base):
							if  self.get_type(base) == FileObject.FILE:
								raise FileExistsError("can not replace file with directory " + base)
						else:
							self.__mkdir(base, mode, retry)
						base = base + self.get_platform().get_separator()
		except Exception, e:
			message = str(e)
			if message.find("Permission denied") > 0:
				raise PermissionDeniedError, path
			elif message.find("File exists") > 0:
				return 
			else:
				raise MakeDirError('can not make dir ' + path, message)
开发者ID:vimov,项目名称:Deployer,代码行数:57,代码来源:ftpbase.py

示例4: get_file

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def get_file(self, local_path, file_path, replace = False, retry = 1):
		"""
		get a file spesified by file path from the server

		@param local_path: local path on local machine where the directory will be checked out
		@param file_path: path of file on subversion  that will be got
		@param replace: if true replaces the existing local working diretory
		@param retry: number of retries before fail

		@raise GetFileError on failure
		"""

		if not Validator.validate_non_empty_string(local_path):
			raise InvalidParameterError("local_path", "Must be non-empty string")
		if not Validator.validate_non_empty_string(file_path):
			raise InvalidParameterError("file_path", "Must be non-empty string")
		if not Validator.validate_boolean(replace):
			raise InvalidParameterError("replace", "Must be a boolean value")
		if not Validator.validate_integer(retry):
			raise InvalidParameterError("retry", "Must be an integer value")

		local_path = self.local_client.get_platform().trim_path(local_path)
		file_path = self.local_client.get_platform().trim_path(file_path)

		if os.path.exists(local_path):
			if os.path.isdir(local_path):
				base_name = self.local_client.get_platform().basename(file_path)
				local_path += self.local_client.get_platform().get_separator() + base_name

		while retry:
			retry -= 1
			try:
				file_str = self.__client.cat(self.repository_path + file_path)
			except:
				if retry == 0:
					raise GetFileError("repository path: ")

			try:
				if os.path.exists(local_path):
					if os.path.isfile(local_path):
						if replace:
							self.local_client.delete(local_path, None, False, True, retry)
						else:
							raise FileExistsError(local_path + " already exists")

				local_file = open(local_path, 'w')
				local_file.write(file_str)
				local_file.close()

			except Exception, e:
				if retry == 0:
					raise FileWriteError ()
			else:
				break
开发者ID:vimov,项目名称:Deployer,代码行数:56,代码来源:subversionclient.py

示例5: rename

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def rename(self, source, destination, retry = 1):
		"""
		rename a file or directory
		
		@param source: the source path to be renamed
		@param destination: the new name of file or dorectory
		@param retry: number of retries on failure
		
		@rtype: bool
		@return: True on success
		
		@raise InvalidParameterError: if parameters are not valid
		@raise FileNotExistsError: if source file or directory is not exist or if create_dirs equal False and destination directory is not exist
		@raise FileExistsError: if the destination exists
		@raise PermissionDeniedError: if the operation is not permitted
		@raise FileRenameError: if error occurred during moving
		"""
		
		if not Validator.validate_non_empty_string(source):
			raise InvalidParameterError("source", "source can not be None or empty string")

		if not Validator.validate_non_empty_string(destination):
			raise InvalidParameterError("destination", "destination can not be None or empty string")
		
		if not Validator.validate_integer(retry):
			raise InvalidParameterError("retry", "retry must be integer")
		
		#add root if the paths is relative 
		source = self.append_to_root(source)
		destination = self.append_to_root(destination)
		
		if self.is_exists(destination):
			raise FileExistsError, destination
		
		while retry > 0:
			retry = retry - 1
			try:
				self.__rename(source, destination)
				return 
			except Exception, e:
				message = str(e)
				if message.find("No such file") > 0:
					raise FileNotExistsError(source)
				elif message.find("Permission denied") > 0:
					raise PermissionDeniedError
				else:
					if retry == 0:
						raise FileRenameError(source + " " + str(e)) 
开发者ID:vimov,项目名称:Deployer,代码行数:50,代码来源:ftpbase.py

示例6: get_last_modified_time

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def get_last_modified_time(self, path):
		"""
		gets the last modification time of a file or directory
		
		@param path: path of directory to
		 
		@rtype: tuple
		@return: last modification time
		
		@raise InvalidParameterError: if parameters are not valid
		@raise FileNotExistsError: if path directory is already exist
		"""	
			
		if False == Validator.validate_non_empty_string(path):
			raise InvalidParameterError('path', 'should be a not empty string')
		
		if not (re.match(r'/', path) or re.match(r'[a-zA-Z]:\\', path)):
			path = path.rstrip(self.get_platform().get_separator())
		if not os.path.exists(path):
			raise FileNotExistsError, 'file or directory not exists'
		
		#test if path is relative
		if self.get_platform().is_relative(path) :
			path = self.__root + path
			
		tmp_time = time.localtime(os.path.getmtime(path))
		
		return datetime(tmp_time[0], tmp_time[1], tmp_time[2], tmp_time[3], tmp_time[4], tmp_time[5],)
开发者ID:vimov,项目名称:Deployer,代码行数:30,代码来源:localclient.py

示例7: __init__

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def __init__(self, url, proxy = None, auth = None, post_encoding = HTTP_METHOD_POST_XWWW_DATA):
		'''
		@param url: the url of the request
		@param proxy: dictionary with two entries have keys ('type' and 'host')
		@param auth: dictionary with four entries have keys ('realm', 'uri', 'user', 'passwd')
		@param ost_encoding : one of types 'Request.HTTP_METHOD_POST_XWWW_DATA' or 'Request.HTTP_METHOD_POST_FORM_DATA'
		'''
		
		if not Validator.validate_non_empty_string(url):
			raise InvalidParameterError("url", "Must be non-empty string")
		if proxy.__class__ != dict and proxy != None:
			raise InvalidParameterError("proxy", "Must be a dictionary")
		if auth.__class__ != dict and auth != None:
			raise InvalidParameterError("auth", "Must be a dictionary")
		
		
		self.method = Request.HTTP_METHOD_GET
		self.url = url
		self.referrer = url
		self.proxy = proxy
		self.auth = auth
		self.post_encoding = post_encoding
		self.data = {}
		self.params = {}
		self.headers = {}
		self.response_validator = []
		self.requested_data = []
		self.cookies = cookielib.CookieJar()
开发者ID:vimov,项目名称:Deployer,代码行数:30,代码来源:browser.py

示例8: to_absolute

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def to_absolute(self, paths):
		"""
		Converts one or more paths to absolute, if they were relative.

		@param paths: Can be a list, or a string.

		@return: A list, or a string, based on the type of the argument.
		"""

		if paths.__class__ == list:

			for i in range(0, len(paths)):
				if self.get_platform().is_relative(paths[i]):
					paths[i] = self.get_platform().join(self.get_root(), paths[i])

			return paths

		elif True == Validator.validate_non_empty_string(paths):

			if self.get_platform().is_relative(paths):
				return self.get_platform().join(self.get_root(), paths)
			else:
				return paths

		else:
			raise InvalidParameterError("paths", "Must be a string or a list.")
开发者ID:vimov,项目名称:Deployer,代码行数:28,代码来源:fileclient.py

示例9: get_last_modified_time

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def get_last_modified_time(self, path, retry = 1):
		'''
		get the last modification time of file using the FTP command MDTM
		
		@param path: path of the file to get the last modification time
		@param retry: number of the retry on the function failure

		@rtype: datetime object
		@type last_modified_time: last modified time of the specified path
		
		@raise InvalidParameterError: If the required argument(s) are not specified. 
		@raise GetLastModificationTimeError: If any failure occurred while performing the command
		@raise FileNotExistError: if the file is not found     
		'''

		if not Validator.validate_non_empty_string(path):
			raise InvalidParameterError("path", "path can not be None or empty string")
		
		if not Validator.validate_integer(retry):
			raise InvalidParameterError("retry", "retry must be integer")

		while retry > 0:
			retry = retry - 1
			try:
				path = self.append_to_root(path)
				__time = self.__get_last_modified_time(path)
				return datetime.datetime(int(__time[0]), int(__time[1]), int(__time[2]), int(__time[3]), int(__time[4]), int(__time[5]))
			except Exception, e:
				message = str(e)
				if message.find('No such file') > 0:
					raise FileNotExistsError, path
开发者ID:vimov,项目名称:Deployer,代码行数:33,代码来源:ftpbase.py

示例10: basename

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def basename(self, path):
		"""
		get the base name of path
		i.e. basename of /a/b/c is c
		i.e. basename of /a/b/c/ is ""
		
		@param paht: path that you want to get the base parent of.
		
		@rtype: string
		@return: the directory parent of the path.
		
		@raise InvalidParameterError: If the path is empty.
		"""
		
		if not Validator.validate_non_empty_string(path):
			raise InvalidParameterError("path", "Cannot be an empty string")
		
		path = self.trim_path(path)
		
		if path[len(path)-1] == self.get_separator():
			return ""
		
		index = path.rfind(self.get_separator())
		name = path[index+1:]
		
		return name
开发者ID:vimov,项目名称:Deployer,代码行数:28,代码来源:_platform.py

示例11: dirname

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def dirname(self, path):
		'''
		get the directrory name of path
		i.e. dirname of /a/b/c is /a/b
		
		@param paht: path that you want to get dirname of it
		@type path: String
		
		@rtype: String
		@return: the dirname of the path
		
		@raise InvalidParameterError: If the required argument(s) are not specified.
		'''

		if not Validator.validate_non_empty_string(path):
			raise InvalidParameterError("path", "Cannot be an empty string")
		
		path = self.trim_path(path)
		
		if path[len(path)-1] == self.get_separator():
			return path
		
		index = path.rfind(self.get_separator())
		name = path[0:index]
		
		return name
开发者ID:vimov,项目名称:Deployer,代码行数:28,代码来源:_platform.py

示例12: run

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def run(self, source, destination, _from, to, excludes = None, chmod = None, delete = False, retry = 1, test_mode = False):
		"""
		run synchronization process
		
		@param source: source server
		@param destination: destination server
		@param _from: path on source server
		@param to: path on destination server
		@param exclude: instance of FileSet
		@param chmod: value for destination files to be chmoded to
		@param delete: if true any files in destination that is non-exist in source will be deleted
		@param test_mode: if true run in test mode
		
		@rtype: bool
		@return: True on success
		
		@raise InvalidParameterError: If one of the arguments is invalid.
		@raise Other: from localclient methods
		"""

		#validating that source or destination are servers and at least one of them is local server
		if source.__class__ != LocalServer:
			raise InvalidParameterError('source', 'Must be instance of LocalServer class')
		if destination.__class__ != FtpServer:
			raise InvalidParameterError('destination', 'Must be instance of FtpSerevr class')
		if not Validator.validate_non_empty_string(_from):
			raise InvalidParameterError('_from', 'Must be non-empty string')
		if not Validator.validate_non_empty_string(to):
			raise InvalidParameterError('to', 'Must be non-empty string')
		if excludes.__class__ != FileSet and excludes != None:
			raise InvalidParameterError('excludes', 'should be instance of FileSet')
		if not Validator.validate_non_empty_string(chmod) and chmod != None:
			raise InvalidParameterError('chmod', 'should be a string value in form like "0777"')
		if not Validator.validate_boolean(delete):
			raise InvalidParameterError('delete', 'should be boolean value')
		if not Validator.validate_boolean(test_mode):
			raise InvalidParameterError('test_mode', 'should be boolean value')
		
		local_platform = source.get_platform()
		ftp_platform = destination.get_platform()

		if not destination.is_exists(to):

				try:
					destination.mkdir(to)
				except Exception, e:
					raise
开发者ID:vimov,项目名称:Deployer,代码行数:49,代码来源:ftpsync.py

示例13: rename

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def rename(self, source, destination, retry = 1):
		"""
		rename a file or dirctory
		
		@param source: the source path to be renamed
		@param destination: the new name of file or dorectory
		@param retry: number of retries befor fail
		
		@rtype: bool
		@return: True on success
		
		@raise InvalidParameterError: if parameters are not valid
		@raise FileNotExistsError: if source file or directory is not exist or if create_dirs equal False and destination directory is not exist
		@raise FileRenameError: if error occurred during moving
		"""
		
		if False == Validator.validate_non_empty_string(source):
			raise InvalidParameterError('source', 'should be a not empty string')
		if False == Validator.validate_non_empty_string(destination):
			raise InvalidParameterError('destination', 'should be a not empty string')
		if retry.__class__ != int:
			raise InvalidParameterError('retry', 'should be an integer value')
		
		#trim the '/' or '\' from the end of path
		source = self.get_platform().trim_path(source)
		
		#test if source is relative
		if self.get_platform().is_relative(source) :
			source = self.__root + source
		
		if not os.path.exists(source):
			raise FileNotExistError, 'the file or directory to be moved is not exist'
		
		while retry:
			retry -= 1
			try:
				parent = self.get_platform().dirname(source)
				destination = parent + self.get_platform().get_separator() + destination
				os.rename(source, destination)
			except Exception, e:
				if retry == 0:
					raise FileRenameError, str(e)
			else:
				break
开发者ID:vimov,项目名称:Deployer,代码行数:46,代码来源:localclient.py

示例14: chmod

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def chmod(self, path, permissions, excludes = None, contents_only = False, recursive = False, retry = 1):
		'''
		Change the permissions of file or directory on ftp server.
		
		@param path: path of the remote file
		@param permissions: target permissions
		@param excludes: the excluded files from the operation
		@param contents_only: boolean for changing the contents of the directory only or also the directory itself
		@param recursive: boolean for chmoding the directory recursively or not
		@param retry: the retry count on failure 
		
		@raise InvalidParameterError: If the required argument(s) are not specified. 
		@raise FileChmodError: If the function fails to chmod the file
		'''

		if not Validator.validate_non_empty_string(path):
			raise InvalidParameterError("path", "path can not be None or empty string")

		if not Validator.validate_non_empty_string(permissions):
			raise InvalidParameterError("permissions", "permissions can not be None or empty string")
		
		path = self.append_to_root(path)
		
		if not self.is_exists(path):
			raise FileNotExistsError, path
		try:
			permissions = self.__get_permissions(permissions)
			excluded = False
			path_type = self.get_type(path)
			if excludes is not None:
				if excludes.match(path, self.get_platform().basename(path), path_type):
					excluded = True
			if not contents_only and not excluded:
				self.__chmod(path, permissions, retry)
				
			if (contents_only or recursive) and path_type is FileObject.DIRECTORY:
				list = self.list(path, excludes,  recursive, retry)
				self.__chmod_list(list, permissions, retry)
		except Exception, e:
			message = str(e)
			if message.find("Operation not permitted") > 0:
				raise PermissionDeniedError
			else:
				raise FileChmodError(path, message)
开发者ID:vimov,项目名称:Deployer,代码行数:46,代码来源:ftpbase.py

示例15: set_default_user_agent

# 需要导入模块: from thedeployer.packages.depfile.validator import Validator [as 别名]
# 或者: from thedeployer.packages.depfile.validator.Validator import validate_non_empty_string [as 别名]
	def set_default_user_agent(cls, user_agent):
		'''
		sets default User Agent for all requests
		
		@param user_agent:
		'''
		
		if not Validator.validate_non_empty_string(user_agent):
			raise InvalidParameterError("user_agent", "Must be non-empty string")
		
		Request.USER_AGENT = user_agent
开发者ID:vimov,项目名称:Deployer,代码行数:13,代码来源:browser.py


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