diff --git a/helpers/bip_helpers.py b/helpers/bip_helpers.py index 04083ced4fca98ef768696d684cc48a2c4b8a93e..bfdce3b6b843e1785fa561ceda4f5938cf8fcfe8 100644 --- a/helpers/bip_helpers.py +++ b/helpers/bip_helpers.py @@ -15,6 +15,7 @@ def get_bip_username(): This function returns BIP username when available or default user when bip can't be loaded :return: user name string formatted user.name """ + try: # from bip.api.system.login import get_user from bip.link.user import get_current_user as get_user @@ -50,12 +51,13 @@ def get_bip_project_settings(): from bip.deprecated.data import Project # from bip.api.system.login import get_user from bip.link.user import get_current_user as get_user - except ImportError as error: - logging.warning("Couldn't load BIP Project, using Default project values. \n Error: {}".format(error)) + logging.warning("Couldn't load BIP Project, using Default project values. \n Import Info: {}".format(error)) return PROJECT_SETTINGS, PROJECT_SETTINGS except AttributeError as error: - logging.warning("Couldn't load BIP Project, using Default project values. \n Error: {}".format(error)) + logging.warning("Couldn't load BIP Project, using Default project values. \n Attribute Info: {}".format(error)) + return PROJECT_SETTINGS, PROJECT_SETTINGS + except: return PROJECT_SETTINGS, PROJECT_SETTINGS else: user = get_user() diff --git a/helpers/local_deployment.py b/helpers/local_deployment.py index 07665bc73efd88bde45d25fa0c2c4c0f959a1fa5..abffa42acfb7109e49676df8bcfb5f7e3da64ed4 100644 --- a/helpers/local_deployment.py +++ b/helpers/local_deployment.py @@ -16,7 +16,6 @@ destination = os.path.join(home, ".nuke", "scripts", "Toolbag") # check if destination folder exists and stop if it doesn't if not os.path.isdir(destination): - # print("{} Doesnt exists. Launch nuke with BIP once".format(destination)) logging.error("{} Doesnt exists. Launch nuke with BIP at least once.".format(destination)) exit() if not os.path.isdir(source): diff --git a/helpers/tech_deployment.py b/helpers/tech_deployment.py new file mode 100644 index 0000000000000000000000000000000000000000..84d9e252ac74fc55c5ec256274753d554f9786a4 --- /dev/null +++ b/helpers/tech_deployment.py @@ -0,0 +1,99 @@ +""" +This scripts copy the content usefull for farm rendering from the user .nuke folder to network availabe path +""" + +from distutils.dir_util import copy_tree +import os +import shutil +import logging +import errno +import stat + +# Verbos +logging.basicConfig() +logging.getLogger().setLevel(logging.DEBUG) +logging.debug("Verbos is ON.") + +# Copy from user .nuke folder +home = os.path.expanduser("~") +source = os.path.join(home, ".nuke") + +# To a network path +destination = r"\\studio\tech\Installers\Foundry\Nuke\tools_temp" + +# Copy only the folders/files needed +directories_to_copy = ['gizmos', 'plugins', 'scripts', 'ToolSets'] +files_to_copy = ['init.py'] + + +# check if destination folder exists and stop if it doesn't +if not os.path.isdir(source): + logging.error("{} Doesnt exists. Launch nuke with BIP at least once.".format(source)) + exit() +if not os.path.isdir(destination): + logging.error("{} Doesnt exists.".format(destination)) + exit() +# get the list of all the stuff to delete +directories_to_delete = [name for name in os.listdir(destination) if os.path.isdir(os.path.join(destination, name))] +files_to_delete = [name for name in os.listdir(destination) if not os.path.isdir(os.path.join(destination, name))] + +# # remove git stuff +# directories_to_delete = [d for d in directories_to_delete if not d.startswith(".")] +# files_to_delete = [f for f in files_to_delete if not f.startswith(".")] + +def handleRemoveReadonly(func, path, exc): + excvalue = exc[1] + if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES: + os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777 + func(path) + else: + raise + +# delete all stuff +try: + for d in directories_to_delete: + logging.info("Deleting {}".format(d)) + shutil.rmtree(os.path.join(destination, d), ignore_errors=False, onerror=handleRemoveReadonly) + for f in files_to_delete: + logging.info("Deleting {}".format(f)) + os.remove(os.path.join(destination, f)) +except OSError as e: + logging.error(e) + pass +try: + total_files = 0 + copied_files = 0 + ignored_folders = [] + ignored_files = [] + for d in directories_to_copy: + for folders, subfolders, files in os.walk(os.path.join(source, d)): + if ".git" not in folders: + for file in files: + if not file.endswith("~"): + total_files += 1 + for d in directories_to_copy: + for folders, subfolders, files in os.walk(os.path.join(source, d)): + if ".git" not in folders: + for file in files: + if not file.endswith("~"): + destination_folder = folders.replace(source, destination) + if not os.path.isdir(destination_folder): + os.makedirs(destination_folder) + shutil.copy(os.path.join(folders, file), destination_folder) + copied_files += 1 + # logging.info("Copying {}".format(file)) + percent = 100*copied_files/total_files + logging.info("Progress: {}% Copying: {}".format(int(percent), file)) + else: + ignored_files.append(file) + else: + ignored_folders.append(folders) + + for f in files_to_copy: + logging.info("Copying {}".format(f)) + shutil.copyfile(os.path.join(source, f), os.path.join(destination, f)) + logging.info("Deployment successful! \n Ignored folders: {} \n Ignored files: {}".format(ignored_folders, ignored_files)) +except OSError as e: + logging.error(e) + pass +