def copy_file(self, src, dst): """ Copy given source to destination Arguments: src (str): the source file which needs to be copied dst (str): the destination of the sourc file Returns: None """ src = self.unc_convert(src) dst = self.unc_convert(dst) src = os.path.normpath(src) dst = os.path.normpath(dst) self.log.debug("Copying file .. {} -> {}".format(src, dst)) dirname = os.path.dirname(dst) try: os.makedirs(dirname) except OSError as e: if e.errno == errno.EEXIST: pass else: self.log.critical("An unexpected error occurred.") raise # copy file with speedcopy and check if size of files are simetrical while True: copyfile(src, dst) if str(getsize(src)) in str(getsize(dst)): break
def _copy_textures(self, textures, destination): for tex in textures: dst = os.path.join(destination, os.path.basename(tex)) t.echo(" - Copy {} -> {}".format(tex, dst)) try: speedcopy.copyfile(tex, dst) except Exception as e: t.echo("!!! Copying failed") t.echo("!!! {}".format(e)) exit(1)
def download_opl_files(self, store_path, files_list=None, project=None, is_sep=False): """ The function download all OPL files in files_list :param store_path: Distance location store OPL :param files_list: list file OPL need to download :param project: project name :param is_sep: :return: None """ if is_sep == False: for project_lr in self.list_project_lr: store_location = os.path.join( store_path, project_lr) # get location store OPL follow project if not os.path.exists(store_location): os.mkdir(store_location) # get list all files in Lr link list_files = os.walk(self.lr_server[project_lr]) # loop all folder , file in list_file_path for root, folders, files in list_files: for file_name in files: if file_name.endswith('.xls') or file_name.endswith( '.xlsx'): # check if file is OPL file or not if len(re.findall(".OPL", file_name)) == 1: # get path file file_path = os.path.join(root, file_name) # get distance file temp_location = os.path.join( store_location, file_name) # check whether file is existed on distance , if existed then delete if os.path.exists(temp_location): os.remove( os.path.join(store_location, file_name)) # shutil.copyfile(file_path, temp_location) # copy file from Lr to local print("Downloading file {}... ".format( file_name)) speedcopy.copyfile(file_path, temp_location)
def copy_file(self, src, dst): """ Copy given source to destination Arguments: src (str): the source file which needs to be copied dst (str): the destination of the sourc file Returns: None """ src = os.path.normpath(src) dst = os.path.normpath(dst) self.log.debug("Copying file .. {} -> {}".format(src, dst)) dirname = os.path.dirname(dst) try: os.makedirs(dirname) except OSError as e: if e.errno == errno.EEXIST: pass else: self.log.critical("An unexpected error occurred.") raise # copy file with speedcopy and check if size of files are simetrical while True: import shutil try: copyfile(src, dst) except shutil.SameFileError as sfe: self.log.critical("files are the same {} to {}".format( src, dst)) os.remove(dst) try: shutil.copyfile(src, dst) self.log.debug("Copying files with shutil...") except (OSError) as e: self.log.critical("Cannot copy {} to {}".format(src, dst)) self.log.critical(e) six.reraise(*sys.exc_info()) if str(getsize(src)) in str(getsize(dst)): break
def install_version(self, openpype_version: OpenPypeVersion, force: bool = False) -> Path: """Install OpenPype version to user data directory. Args: oepnpype_version (OpenPypeVersion): OpenPype version to install. force (bool, optional): Force overwrite existing version. Returns: Path: Path to installed OpenPype. Raises: OpenPypeVersionExists: If not forced and this version already exist in user data directory. OpenPypeVersionInvalid: If version to install is invalid. OpenPypeVersionIOError: If copying or zipping fail. """ if self.is_inside_user_data(openpype_version.path) and not openpype_version.path.is_file(): # noqa raise OpenPypeVersionExists( "OpenPype already inside user data dir") # determine destination directory name # for zip file strip suffix, in case of dir use whole dir name if openpype_version.path.is_dir(): dir_name = openpype_version.path.name else: dir_name = openpype_version.path.stem destination = self.data_dir / dir_name # test if destination directory already exist, if so lets delete it. if destination.exists() and force: try: shutil.rmtree(destination) except OSError as e: self._print( f"cannot remove already existing {destination}", LOG_ERROR, exc_info=True) raise OpenPypeVersionIOError( f"cannot remove existing {destination}") from e elif destination.exists() and not force: raise OpenPypeVersionExists(f"{destination} already exist.") else: # create destination parent directories even if they don't exist. destination.mkdir(parents=True) # version is directory if openpype_version.path.is_dir(): # create zip inside temporary directory. self._print("Creating zip from directory ...") with tempfile.TemporaryDirectory() as temp_dir: temp_zip = \ Path(temp_dir) / f"openpype-v{openpype_version}.zip" self._print(f"creating zip: {temp_zip}") self._create_openpype_zip(temp_zip, openpype_version.path) if not os.path.exists(temp_zip): self._print("make archive failed.", LOG_ERROR) raise OpenPypeVersionIOError("Zip creation failed.") # set zip as version source openpype_version.path = temp_zip elif openpype_version.path.is_file(): # check if file is zip (by extension) if openpype_version.path.suffix.lower() != ".zip": raise OpenPypeVersionInvalid("Invalid file format") if not self.is_inside_user_data(openpype_version.path): try: # copy file to destination self._print("Copying zip to destination ...") _destination_zip = destination.parent / openpype_version.path.name # noqa: E501 copyfile( openpype_version.path.as_posix(), _destination_zip.as_posix()) except OSError as e: self._print( "cannot copy version to user data directory", LOG_ERROR, exc_info=True) raise OpenPypeVersionIOError(( f"can't copy version {openpype_version.path.as_posix()} " f"to destination {destination.parent.as_posix()}")) from e # extract zip there self._print("extracting zip to destination ...") with ZipFile(openpype_version.path, "r") as zip_ref: zip_ref.extractall(destination) return destination