def __init__(self, source_path='', *args): """ Constructor of main GUI for FR_RiggingTool """ # Convert ui path file as FrFile Object ui_file = path.Path(__file__).parent / 'AboutFrMaya.ui' super(MainGUI, self).__init__(ui_file, title_tool='About FrMaya', *args) self.source_path = path.Path(source_path) self.connect_event_handlers()
def find_malware_files(): """ Collect all script files that breed the malware. :rtype: list of path.Path """ maya_user_dir = path.Path(pm.internalVar(userAppDir=True)) user_setup_mel = maya_user_dir / 'scripts' / 'userSetup.mel' user_setup_py = maya_user_dir / 'scripts' / 'userSetup.py' user_setup_mel_data = util.read_file_text( user_setup_mel) if user_setup_mel.exists() else '' user_setup_py_data = util.read_file_text( user_setup_py) if user_setup_py.exists() else '' vaccine_py = maya_user_dir / 'scripts' / 'vaccine.py' vaccine_pyc = maya_user_dir / 'scripts' / 'vaccine.pyc' malware_files = [] if 'fuck_All_U' in user_setup_mel_data: malware_files.append(user_setup_mel) if 'leukocyte' in user_setup_py_data and 'vaccine' in user_setup_py_data: malware_files.append(user_setup_py) if os.path.exists(vaccine_py): malware_files.append(vaccine_py) if os.path.exists(vaccine_pyc): malware_files.append(vaccine_pyc) return malware_files
def _texture_file_pattern_to_glob(input_path): """Takes an image file path and returns it in glob format if the file path has pattern, with the pattern replaced by a '*'. Image file path may be numerical sequences, e.g. /path/to/file.1001.exr will return as /path/to/file.*.exr. Image file path may also use tokens to denote sequences, e.g. /path/to/texture.<UDIM>.tif will return as /path/to/texture.*.tif. Based from Big roy github gist https://gist.github.com/BigRoy/d027323b27bf9de8f92a7c2ea972122a :arg input_path: Image file path need to process. :type input_path: str or path.Path :rtype: path.Path """ input_path = path.Path(input_path) # If any of the patterns, convert the pattern patterns = { "<udim>": "<udim>", "<tile>": "<tile>", "<uvtile>": "<uvtile>", "#": "#", "u<u>_v<v>": "<u>|<v>", "<frame0": "<frame0\\d+>", "<f>": "<f>" } lower = input_path.lower() has_pattern = False for pattern, regex_pattern in patterns.items(): if pattern in lower: input_path = re.sub(regex_pattern, "*", input_path, flags=re.IGNORECASE) has_pattern = True if has_pattern: return path.Path(input_path) else: # pattern not found return input_path
def update_released(self): mssg = 'Installed version : ' mssg += '{}\t\n'.format(FrMaya.version()) mssg += 'Server version : ' mssg += '{}\t\n\n'.format('.'.join( str(x) for x in fmc.get_server_version())) if self.check_update(): mssg += 'New version available!!' btn_list = ['Yes', 'No'] else: mssg += 'No new version.' btn_list = ['Ok'] result = pm.confirmDialog(t='FrMaya Update', b=btn_list, m=mssg, messageAlign='left') message = '' try: if result == 'Yes': zip_file, new_frmaya_dir = fmc.download_latest_version( target_name='FrMaya') new_frmaya_dir = new_frmaya_dir / 'FrMaya-master' # check if its local frmaya_local = fmc.check_local_package('FrMaya') if frmaya_local: fmc.install(new_frmaya_dir, package_title='FrMaya', local_install=True) else: old_package_dir = path.Path(FrMaya.basedir()).parent shutil.rmtree(old_package_dir, ignore_errors=True) if not old_package_dir.exists(): old_package_dir.mkdir() # use this method instead of copy tree from the root directory to avoid error for src_item in new_frmaya_dir.listdir(): nama = src_item.name tgt_item = old_package_dir / nama if src_item.isdir(): shutil.copytree(src_item.abspath(), tgt_item.abspath()) elif src_item.isfile(): shutil.copy(src_item.abspath(), tgt_item.abspath()) fmc.install(old_package_dir, package_title='FrMaya') message = 'FrMaya succesfuly updated.\nPlease restart maya.' except Exception as e: message = 'FrMaya failed to update.\n{0}'.format(e) if result == 'Yes': # show result of updating frmaya pm.confirmDialog(t='FrMaya info', m=message, b=['Ok'], db='Ok')
def get_file_node_path(texture_file_node): """Get file path from file node, preserve pattern format such as <udim> or <f>. :arg texture_file_node: File pynode that need to get file path extracted. :type texture_file_node: pm.PyNode :rtype: path.Path """ # use computedFileTextureNamePattern attr instead fileTextureName, # this preserves the <> tag / format pattern if texture_file_node.hasAttr('computedFileTextureNamePattern'): texture_pattern = texture_file_node.attr( 'computedFileTextureNamePattern').get() patterns = [ "<udim>", "<tile>", "u<u>_v<v>", "<f>", "<frame0", "<uvtile>" ] lower = texture_pattern.lower() if any(pattern in lower for pattern in patterns): return path.Path(texture_pattern) # otherwise use fileTextureName return path.Path(texture_file_node.attr('fileTextureName').get())
def create_control(control_file, transform=None, name='FrControl', suffix='Ctl', group=None): """Create control curve for FrMaya rig. :arg control_file: Control file absolute path or control file name. :type control_file: path.Path or str :key transform: Sets transformation of the newly-created control. Default use world transform. :type transform: pm.dt.Matrix :key name: Sets the name of the newly-created control. :type name: str :key suffix: Add suffix to the name. :type suffix: str :key group: Sets group chain on newly-created control. :type group: list of str :return: ControlTuple(control = control_curve, group_data = group_dict_data) :rtype: (pm.nt.Transform, dict of pm.nt.Transform) """ if transform is None: transform = pm.dt.Matrix() if group is None: group = [] # if control_file is file name of control grab it from get_control_files control_file_path = path.Path(control_file) if not control_file_path.exists(): control_file_path = get_control_files(control_file)[0] # add suffix to name name += '_' + suffix # read control file control_data = util.read_json(control_file_path) # build control curve curve_control = general.build_curve(control_data) # rename control curve_control.rename(name) # retransform control curve_control.setMatrix(transform, worldSpace=True) # pgroup the control resgrp = {} input_grp = curve_control for o in group: resgrp[o] = general.pgroup([input_grp], re=suffix, suffix=o)[0] input_grp = resgrp[o] suffix = o # create control tuple class ControlTuple = collections.namedtuple('ControlTuple', 'control group_data') # create instance of control tuple and assign the value result = ControlTuple(control=curve_control, group_data=resgrp) return result
def __init__(self, *args): """ Constructor of main GUI for FR_RiggingTool """ # Convert ui path file as FrFile Object ui_file = path.Path(__file__).parent / 'FR_RiggingTool.ui' super(MainGUI, self).__init__(ui_file, title_tool='FR_RiggingTool', *args) self.connect_event_handlers() self.docking()
def check_local_package(installed_title): """Check installed package in Maya user application directory. :return: True if its exists, Falser otherwise :rtype: bool """ user_app_dir = path.Path(pm.internalVar(uad=True)) installed_dir = user_app_dir / installed_title if installed_dir.isfile(): return False elif installed_dir.isdir(): return True else: return False
def download_latest_version(target_name='', target_dir=None): """Download latest FrMaya version from github. :key target_name: Zip or directory new downloaded data. :type target_name: str :key target_dir: Directory where the download will placed. :type target_dir: str or path.Path :return: FrMaya master zip and FrMaya extracted zip file. :rtype: tuple of path.Path """ url_address = 'https://github.com/muhammadfredo/FrMaya/archive/master.zip' if target_dir is None: temp_dir = path.Path(tempfile.gettempdir()) else: temp_dir = path.Path(target_dir) temp_frmaya_zip = temp_dir / '{}.zip'.format(target_name) temp_frmaya_dir = temp_dir / target_name with open(temp_frmaya_zip, 'wb') as temp_zip: temp_zip.write(urllib2.urlopen(url_address).read()) zipfile.ZipFile(temp_frmaya_zip).extractall(temp_frmaya_dir) return path.Path(temp_frmaya_zip).abspath(), path.Path( temp_frmaya_dir).abspath()
def uninstall(installed_title): """Uninstall FrMaya package. :arg installed_title: FrMaya package title name. :type installed_title: str """ assert installed_title, 'Package title not found!!!' assert installed_title != 'maya', '{} is not package!!'.format( installed_title) # Maya user application directory user_app_dir = path.Path(pm.internalVar(uad=True)) # modules dir module_dir = user_app_dir / 'modules' module_file = module_dir / '{}.mod'.format(installed_title) if module_file.exists(): module_file.remove() # installed package installed_pkg = user_app_dir / installed_title if installed_pkg.exists(): shutil.rmtree(installed_pkg, ignore_errors=True)
def __get_environ_path(environ_key): """Collect path from given environment key.""" environ_value = os.environ.get(environ_key) result = [] if not environ_value: return result environ_path_list = environ_value.split(';') for each_path in environ_path_list: each_path = path.Path(each_path) if not each_path.exists(): continue # make sure default directory first in the order if 'FrMaya' in each_path: result.insert(0, each_path) else: result.append(each_path) return result
def backup_file(file_path): """Backup supplied file into file.versions folder and add version number on their file name. :arg file_path: Source file (absolute path) which need to get backup. :type file_path: str or path.Path :return: Latest backup file (absolute path). :rtype: path.Path """ file_path = path.Path(file_path) dir_path = file_path.parent file_name = file_path.stem file_ext = file_path.ext # backup directory backup_dir = dir_path / '{}.versions'.format(file_name) # detect if backup directory exist if not backup_dir.exists(): backup_dir.makedirs() backup_file_glob = backup_dir.glob('{}.v*{}'.format(file_name, file_ext)) version_count = 1 if backup_file_glob: backup_file_glob.sort() latest_file = backup_file_glob[-1] version_count = int( latest_file.stem.replace('{}.v'.format(file_name), '')) version_count += 1 # new version file backup_file_path = backup_dir / '{}.v{:03d}{}'.format( file_name, version_count, file_ext) # copy the file / backup the file file_path.copyfile(backup_file_path) return backup_file_path.abspath()
def set_source_path(self, input_path): source_path = path.Path(input_path) self.source_path = source_path
def install(source_path, package_title='', local_install=False): """Install FrMaya package. :arg source_path: Downloaded or cloned FrMaya package absolute path. :type source_path: str or path.Path :key package_title: Package name. :type package_title: str :key local_install: If True, FrMaya package will be copied into maya user application directory. :type local_install: bool :rtype: bool """ frmaya_content = [ 'FrMaya', 'MayaMenubar', 'RigData', 'startup', 'LICENSE.txt', 'README.md' ] source_path = path.Path(source_path).abspath() if package_title: installed_title = package_title else: installed_title = source_path.name assert source_path.exists(), 'Source path did not exist!!!' assert installed_title, 'Package title not found!!!' for each in frmaya_content: sub_item = source_path / each assert sub_item.exists( ), '{} did not exists, make sure its exists!!'.format(sub_item) # Maya user application directory user_app_dir = path.Path(pm.internalVar(uad=True)) # create modules dir module_dir = user_app_dir / 'modules' if not module_dir.exists(): module_dir.mkdir() # uninstall first if any uninstall(installed_title) if local_install: # FrMaya script folder path target_dir = user_app_dir / installed_title # create FrMaya root dir if not target_dir.exists(): target_dir.mkdir() # copy all sub content into target_dir for each in frmaya_content: src = source_path / each tgt = target_dir / each if src.isdir(): shutil.copytree(src.abspath(), tgt.abspath()) elif src.isfile(): shutil.copy(src.abspath(), tgt.abspath()) else: target_dir = source_path # write module file module_file = module_dir / '{}.mod'.format(installed_title) with open(module_file, 'w') as ss: ss.write('+ FrMaya any {}\n'.format(target_dir)) ss.write('scripts+:=startup\n') ss.write('PYTHONPATH+:=\n') ss.write('PYTHONPATH+:=startup\n') ss.write('MAYA_SCRIPT_PATH+:=startup\n') ss.write('FR_MYMENUBAR+:=MayaMenubar\n') ss.write('FR_CONTROLCURVE+:=RigData\\ControlCurve\n') return True
def __init__(self, *args): # Convert ui path file as FrFile Object ui_file = path.Path(__file__).parent / 'FR_InstallTool.ui' super(MainGUI, self).__init__(ui_file, *args)