本文整理汇总了Python中thedeployer.packages.depfile.validator.Validator类的典型用法代码示例。如果您正苦于以下问题:Python Validator类的具体用法?Python Validator怎么用?Python Validator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Validator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_last_modified_time
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,代码行数:31,代码来源:ftpbase.py
示例2: __init__
def __init__(self, id, address, port, document_root, language):
"""
Constructor for the class.
@param id: The identifier of this server, must be a non-empty string.
@param address: The web address (excluding the protocol, for the web server.
@param port: The port of the server.
@param document_root: The document root of the server.
@param language: A language this server supports, like PHP5.
"""
if not Validator.validate(address, 'domain'):
raise InvalidParameterError('address', 'Must be a valid domain name, excluding the protocol or path.')
if not Validator.validate(port, 'port'):
raise InvalidParameterError('port', 'Must be an integer value between 0 and 65535')
if not Validator.validate(document_root, 'non_empty_string'):
raise InvalidParameterError('document_root', 'Must be a non-empty string')
if not Validator.validate(language, 'non_empty_string'):
raise InvalidParameterError('language', 'Must be a non-empty string')
self.__address = address
self.__port = port
self.__document_root = document_root
self.__language = language
Server.__init__(self, id, Server.REMOTE)
WebClient.__init__(self)
开发者ID:vimov,项目名称:Deployer,代码行数:27,代码来源:server.py
示例3: put
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,代码行数:60,代码来源:ftpbase.py
示例4: __init__
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,代码行数:27,代码来源:sshclient.py
示例5: mkdir
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,代码行数:55,代码来源:ftpbase.py
示例6: get_file
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,代码行数:54,代码来源:subversionclient.py
示例7: create_db
def create_db(self, name, character_set = "", collate = "", if_not_exists = True, retry = 1):
"""
creates new database using data base name, character_set, and collate
@param name: name of database to be created
@param character_set: character set of the database
@param collate: the collation of the database
@param if_not_exist: only creates the database if it does not exist
@param retry: The number of times to retry execution on error
@rtype: bool
@return: True on success
@raise InvalidParameterError: If method parameters are invalid in type.
@raise DbCreateError: if failed to create the database.
"""
if False == Validator.validate_non_empty_string(name):
raise InvalidParameterError('name', 'name should be a non-empty string')
if False == Validator.validate_string(character_set):
raise InvalidParameterError('character_set', 'character_set should be a string')
if False == Validator.validate_string(collate):
raise InvalidParameterError('collate', 'collate should be a string')
if False == Validator.validate_boolean(if_not_exists):
raise InvalidParameterError('if_not_exist', 'should be a boolean')
while True:
try:
statement = "CREATE DATABASE %s %s"
conn = MySQLdb.connect(host = self.__host, user = self.__username, passwd = self.__password, port = self.__port)
transaction = conn.cursor()
if True == if_not_exists:
statement = statement % ("IF NOT EXISTS", name)
else:
statement = statement % ("", name)
if 0 != len(character_set):
statement = statement + " CHARACTER SET = %s " % (character_set)
if 0 != len(collate):
statement = statement + " COLLATE = %s " % (collate)
AppLogger.debug('Executing SQL command "%s"' % (statement))
transaction.execute(statement)
return True
except Exception, e:
retry = retry - 1
if 0 == retry:
raise DbCreateError, str(e)
开发者ID:vimov,项目名称:Deployer,代码行数:52,代码来源:mysqlclient.py
示例8: export
def export(self, local_path, path = "/", revision = 0, retry = 1):
"""
export a directory from the subversion server that is spesified by path parameter
@param local_path: local path on local machine where the directory will be checked out.
@param path: path of directory on subversion servern that will be checked out.
@param replace: if true replaces the existing local working diretory.
@param revision: revision number to checkout, 0 to checkout the last revision.
@param retry: number of retries before fail.
@raise CheckOutError in case of failure
"""
if not Validator.validate_non_empty_string(local_path):
raise InvalidParameterError("local_path", "Must be non-empty string")
if not Validator.validate_string(path):
raise InvalidParameterError("path", "Must be a string value")
if not Validator.validate_integer(revision):
raise InvalidParameterError("revision", "Must be an integer value")
if not Validator.validate_integer(retry):
raise InvalidParameterError("retry", "Must be an integer value")
export_path = os.path.join(self.repository_path, path.lstrip("/"))
if os.path.exists(local_path):
raise FileExistsError, "the path where you check out is already exists"
while True:
try:
if 0 == revision:
return self.__client.export(
export_path,
local_path,
True,
)
else:
return self.__client.export(
export_path,
local_path,
True,
pysvn.Revision(pysvn.opt_revision_kind.number, revision)
)
except Exception, e:
retry -= 1
if 0 == retry:
raise CheckOutError(
'Failed to export "%s" to "%s"."' % (export_path, local_path)
)
else:
shutil.rmtree(local_path, True)
开发者ID:vimov,项目名称:Deployer,代码行数:52,代码来源:subversionclient.py
示例9: rename
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,代码行数:48,代码来源:ftpbase.py
示例10: execute_sql
def execute_sql(self, statements, database, transaction = False):
"""
Executes a sequence of SQL statements.
@param statements: list of statements to be executed.
@param database: the name of the database to run the statements.
@param transaction: if it is True, statements will be executed as a single transaction.
@rtype: bool
@return: True on success
@raise InvalidParameterError: If method parameters are invalid in type.
@raise DbStatementError: if method fails in executing statements or connecting to database.
"""
if statements.__class__ != list:
raise InvalidParameterError('statements', 'statements should be a list of statements')
if False == Validator.validate_non_empty_string(database):
raise InvalidParameterError('database', 'must be a non empty string')
if False == Validator.validate_boolean(transaction):
raise InvalidParameterError('transaction', 'must be a boolean')
while True:
try:
cursor = None
conn = MySQLdb.connect(host = self.__host, user = self.__username, passwd = self.__password, port = self.__port, db = database)
cursor = conn.cursor()
for statement in statements:
cursor.execute(statement)
if not transaction:
conn.commit()
cursor.close()
conn.commit()
conn.close()
return True
except Exception, e:
if cursor:
cursor.close()
conn.rollback()
conn.close()
raise DbStatementError, str(e)
开发者ID:vimov,项目名称:Deployer,代码行数:48,代码来源:mysqlclient.py
示例11: get_last_modified_time
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,代码行数:28,代码来源:localclient.py
示例12: __init__
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,代码行数:28,代码来源:browser.py
示例13: basename
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,代码行数:26,代码来源:_platform.py
示例14: dirname
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,代码行数:26,代码来源:_platform.py
示例15: to_absolute
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,代码行数:26,代码来源:fileclient.py
示例16: run
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,代码行数:47,代码来源:ftpsync.py
示例17: chown
def chown(self, path, owner, group, excludes = None, contents_only = False, recursive = False, retry = 1):
'''
changing the ownership of file
@param path: file path
@param owner: the target owner id of the file
@param group: the target group id of the file
@param excludes: list of the excluded file from the operation
@param contents_only: if True the contents of the file only will be changed not the file itself
@param recursive: if True the operation will be done recursively
@param retry: the number of retries on function failure
@raise InvalidParameterError: If the required argument(s) are not specified.
@raise FileNotExistError: if the path is not exist
@raise FtpChownError: If the ownership can not be changed
'''
if not Validator.validate_non_empty_string(path):
raise InvalidParameterError("path", "path can not be None or empty string")
if not Validator.validate_integer(owner):
raise InvalidParameterError("owner", "owner can not be None or empty string")
if not Validator.validate_integer(group):
raise InvalidParameterError("group", "group can not be None or empty string")
try:
path = self.append_to_root(path)
if not self.is_exists(path):
raise FileNotExistsError, path
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.__chown(path, owner, group, retry)
if recursive and path_type is FileObject.DIRECTORY:
children = self.list(path, excludes, True, retry)
self.__chown_list(child.get_path(), owner, group, retry)
except Exception, e:
raise FileChownError(path, str(e))
开发者ID:vimov,项目名称:Deployer,代码行数:45,代码来源:ftpbase.py
示例18: set_default_timeout
def set_default_timeout(cls, timeout):
'''
sets default timeout for all requests
'''
if not Validator.validate_integer(timeout):
raise InvalidParameterError("timeout", "Must be an integer value")
socket.setdefaulttimeout(timeout)
开发者ID:vimov,项目名称:Deployer,代码行数:9,代码来源:browser.py
示例19: chmod
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,代码行数:44,代码来源:ftpbase.py
示例20: rename
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,代码行数:44,代码来源:localclient.py
注:本文中的thedeployer.packages.depfile.validator.Validator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论