def _init_root_path(self): if self._userInfo == None: return False toCheck = [self._userInfo.local_area, self._userInfo.log_dir] checkLayout = False for d in toCheck: if not DiskUtils.is_dir_exist(d): checkLayout = True MsgUtils.warning("%r is needed, create..." % d) if DiskUtils.create_path_rec(d) == False: MsgUtils.error("can't create %r" % d) else: MsgUtils.info("%r created" % d) #only on creation,copy if exist the defaultLayoutFile from # from the module if checkLayout: import shutil fromlayout = os.path.join(self._resource.resource_path, initDefault.DEFAULT_LAYOUT_ROOT) tolayout = os.path.join(self._userInfo.local_area, initDefault.DEFAULT_LAYOUT_ROOT) fromlayout += ".lyt" tolayout += ".lyt" if os.path.exists(fromlayout) and not os.path.exists(tolayout): shutil.copyfile(fromlayout, tolayout) MsgUtils.info("found a defaut layout file %s" % fromlayout) self.valid_to_save = self.is_persistant()
def inspect_asset_depend(self, showobj, assobj): typeList = getAssetMapping(showobj.getName()) SW.start() allready = assobj.get_publishedType() allready = [x.getName() for x in allready] typeListMissing = OrderedDict() for i in typeList: if not typeList[i].short_name in allready: typeListMissing[i] = typeList[i].short_name if len(typeListMissing) == 0: SW.stop() if self.verbose: log.info("assetid_filepub_query in {}".format(SW.elapsed())) return file_type_obj_list = self._get_ft(typeListMissing) pf_list = self.assetid_filepubobj_query(showobj, assobj, file_type_obj_list) for k, pf in zip(typeListMissing.keys(), pf_list): # update data list assobj.set_plublished_type(typeListMissing[k], pf) SW.stop() if self.verbose: log.info("assetid_filepub_query in {}".format(SW.elapsed()))
def __init__(self, shot_only=False, asset_only=False, verbose=False): """Create an instance, (simple fast nothing important :param shot_only: if True will not load asset :param asset_only: if True will not load shot :param verbose: display query timing information to database """ if shot_only == True: log.info("*" * 20 + " running query for shot only " + "*" * 20) if asset_only == True: log.info("*" * 20 + " running query for asset only " + "*" * 20) super(DbCache, self).__init__() self._shot_only = shot_only self._asset_only = asset_only self.verbose = verbose self.reset() self._asset_type = list() self._group_perm = list() self._cache_group = dict( ) # to build temporary cache for pipeline config
def inspect_shot_depend(self, showobj, shotobj): """Load the needed filepublish :param showobj: a ShowInfoDb object :param shotobj: a ShotInfoDb object """ SW.start() # this needs to isolated typeList = getShotMapping(showobj.getName()) allready = shotobj.get_publishedType() allready = [x.getName() for x in allready] typeListMissing = OrderedDict() for i in typeList: if not typeList[i].short_name in allready: typeListMissing[i] = typeList[i].short_name if len(typeListMissing) > 0: file_type_obj_list = self._get_ft(typeListMissing) pf_list = self.shotid_filepubobj_query(showobj, shotobj, file_type_obj_list) for k, pf in zip(typeListMissing.keys(), pf_list): shotobj.set_plublished_type(typeListMissing[k], pf) SW.stop() if self.verbose: log.info("shotid_filepub_query in {}".format(SW.elapsed()))
def inspect_shot_asset_depend(self, showobj, assetobj): """Load the needed filepublish :param showobj: a ShowInfoDb object :param assetobj: a AssetInfoDb object """ typeList = getAssetMapping(showobj.getName()) assets_name = assetobj.get_asset_names() asset_obj_list = showobj.load_asset_if_not(self, assets_name) SW.start() for assobj in asset_obj_list: allready = assobj.get_publishedType() allready = [x.getName() for x in allready] typeListMissing = OrderedDict() for i in typeList: if not typeList[i].short_name in allready: typeListMissing[i] = typeList[i].short_name if len(typeListMissing) == 0: continue file_type_obj_list = self._get_ft(typeListMissing) pf_list = self.assetid_filepubobj_query(showobj, assobj, file_type_obj_list) for k, pf in zip(typeListMissing.keys(), pf_list): # update data list assobj.set_plublished_type(typeListMissing[k], pf) SW.stop() if self.verbose: log.info("assetid_filepub_query in {}".format(SW.elapsed()))
def get_current_confpipe(self, showobj): SW.start() res = showobj.get_current_confpipe(self) SW.stop() if self.verbose: log.info("get_current_confpipe in {}".format(SW.elapsed())) return res
def _push_new_version(self, gitrepo): """ Query, increment tag and push to remote repo """ x = GitUtils(gitrepo) ver = x.get_git_version() if ver in ["", "NONE"]: ver = "v0.0.0" else: verob = DirVersioned(ver) if verob.is_valid(): verob.inc_patch() # need an argument for minor ver = verob.format() glog = x.get_git_log(20) # we only push if head is not tagged do_tag = True for l in glog: log.info("log check for HEAD %s" % l) if l[-1] == True: log.warning("HEAD is already tag, will not create new tag") do_tag = False break if do_tag: x.create_tag(ver) x.push_tag(ver) log.info("new tag will be created: %r" % x.get_git_version())
def H_loadLayout(widgetApp, editor, aDefautPathMgr, nameLayout): if nameLayout == "": log.info("not layout file specified") widgetApp.resize(500, 500) widgetApp.move(100, 100) return afile = editor.layout_file(nameLayout) if not DiskUtils.is_file_exist(afile): afile = aDefautPathMgr.getDefaultLayoutFile() if not DiskUtils.is_file_exist(afile): log.debug("cannot find the layout file %s" % afile) widgetApp.resize(500, 500) widgetApp.move(100, 100) return settings = QtT.QtCore.QSettings(afile, QtT.QtCore.QSettings.IniFormat, None) if DO_PYQT4: widgetApp.resize(settings.value('MainWindow/size').toSize()) widgetApp.move(settings.value('MainWindow/pos').toPoint()) widgets = list( map(str, settings.value('MainWindow/widgets').toStringList())) for w in widgets: className = str(settings.value('%s/className' % w).toString()) widgetApp.toolInstanciate(className, w) widgetApp.restoreState( settings.value('MainWindow/state').toByteArray()) for w in widgets: if w in widgetApp._docksWidget: widgetApp._docksWidget[w].getCustomWidget().resize( settings.value('%s/size' % w).toSize()) isFloating = settings.value('%s/floating' % w).toBool() if isFloating: widgetApp._docksWidget[w].getCustomWidget().move( settings.value('%s/pos' % w).toPoint()) else: widgetApp.resize(settings.value('MainWindow/size')) widgetApp.move(settings.value('MainWindow/pos')) widgets = settings.value('MainWindow/widgets') if widgets != None: for w in widgets: className = str(settings.value('%s/className' % w)) widgetApp.toolInstanciate(className, w) widgetApp.restoreState(settings.value('MainWindow/state')) for w in widgets: if w in widgetApp._docksWidget: widgetApp._docksWidget[w].getCustomWidget().resize( settings.value('%s/size' % w)) isFloating = settings.value('%s/floating' % w) if isFloating: widgetApp._docksWidget[w].getCustomWidget().move( settings.value('%s/pos' % w))
def _do_users(self): """ query and cache step info """ SW.start() conn = self.get_conn() if self.verbose: log.warning("login to shotgun, to get user") step = SQ.user_info_with_id(conn=conn) parent = self['Users'] for s in step: parent.addChild(s, withRename=False) SW.stop() if self.verbose: log.info("user_query in {}".format(SW.elapsed()))
def createItem(self, text, parent, index,extraData=None): log.info("CreateItem %s %s %s" % (text,parent,index)) after = None if index != 0: after = self.childAt(parent, index - 1) if parent is not None: item = QtT.QtWidgets.QTreeWidgetItem(parent, after) else: item = QtT.QtWidgets.QTreeWidgetItem(self, after) item.setText(0,text) self.iconSet(item,extraData) if self._editable: item.setFlags(item.flags() | QtT.QtCore.Qt.ItemIsEditable) return item
def pull_repo(self, repo_name, dest, branch=""): """This function is not checking the validity of self :param repo_name: (str) a valid git address relative_destination: (str) folder under _repolocation :param branch: optional branch name :return: return log of the git call """ cmd = ['git'] if branch != "": cmd.append("-b %s" % branch) cmd.extend(["pull", repo_name]) log.info("fetch: %s" % " ".join(cmd)) p = self._callsubprocess(cmd, self._repolocation) result = self._getresult(p, cmd) return result
def _do_steps(self): """Query and cache step info """ conn = self.get_conn() if conn == None: return SW.start() if self.verbose: log.warning("login to shotgun, to get default step settings") steps = SQ.step_list_with_id(conn) parent = self['Steps'] steps_name = dict() for s in steps: if not s.getName() in steps_name: steps_name[s.getName()] = s for s in steps_name: parent.addChild(steps_name[s], withRename=False) SW.stop() if self.verbose: log.info("step_query in {}".format(SW.elapsed()))
def load_tp_file(cls, tpZipFile, searchPath=None, group=True): # init tp fileToLoad = tpZipFile doSearch = False # if there is a searchPath and the file doesn't have a path if searchPath != None and fileToLoad.find(os.sep) == -1: doSearch = True if isinstance(searchPath, basestring): searchPath = [searchPath] for i in searchPath: p = os.path.join(i, tpZipFile) if os.path.isfile(p) == True: fileToLoad = p break if doSearch and fileToLoad == tpZipFile: log.warning( "couln't find the package %r at this location, maybe a new package" % tpZipFile) log.info("loading %r" % fileToLoad) return cls.open_tp(fileToLoad)
def download_icon(self, image_url, dest): SW.start() SQ.download_icon(image_url, dest, self.get_conn()) SW.stop() if self.verbose: log.info("download icon in {}".format(SW.elapsed()))
def get_log_file(self): if self._homeUser != "": return self._homeUser.get_log_file() log.info("noLogFile") return ""
def get_recent_file(self): if self._homeUser != "": return self._homeUser.get_recent_file() log.info("no recentfile path defined") return ""
def __init__(self,**options): super(UserProfile,self).__init__() self.reset() # check for cfd as to see if this is a debug mode configdata = options.get('cfd',None) if options else None if configdata: self.debug = configdata.debug self._sgtkutils = None ''' if configdata != None: try: self._sgtkutils = configdata.sgtkutil except: pass if self._sgtkutils and self.debug == True: self._sgtkutils.print_info(self.debug) ''' self.appName = options.get('appName', '') self.subType = options.get('subType', '') rootpath = options.get('userBase', initDefault.HOME_PREF) initmodule = options.get("initModule",None) self.options = options # check if initmodule carry the missing key if self.appName == "": if hasattr(initmodule,'appName'): self.appName = initmodule.appName if self.subType == "": if hasattr(initmodule,'subType'): self.subType = initmodule.subType if rootpath == "": if hasattr(initmodule,'userBase'): rootpath = initmodule.userBase assert isinstance(self.appName, str) assert isinstance(self.subType, str) assert isinstance(rootpath, str) and os.path.isdir(rootpath) #MsgUtils.info("init homeUser %r" % self.appName) self._about = get_about(self.appName, initmodule) self._resource = get_resources_locations(initmodule) self._userInfo = get_user_info(self.appName, self.subType, rootpath, initmodule) self.rootpath = self._userInfo.local_area self._support = get_support(self.appName, self.subType, initmodule) if self.appName == "": MsgUtils.info("no pref are saved") return # build the user are if possible self._init_root_path()
def pack_commit(self, fromdir, todir, packname, top_release_path, repo_name, version, with_version=True): """ :param fromdir: (str path) an envi user_place ex: BaseEnv.user_home('eric') :param todir: (str path) an envi release place ex: BaseEnv.base() :param packname: (str) the name of the pack :param top_release_path: (str path) the release area of all repo: ex: /mnt/dev/${USER}/packages :param repo_name: (str) dir name of the repo. ex: mgtk-multi-setuptools :param version: (str) version ex: v0.0.8 :param with_version=True NOT DONE :return ResultFileProc: """ if not os.path.isdir(todir): return ResultFileProc(False, ["Doesn't exist %s" % todir], [], None) searchPath1 = [todir] if not isinstance(fromdir, list): searchPath2 = [fromdir] else: searchPath2 = fromdir fromFile = toFile = "" pi = PackInfo(packname) rcHome = pi.real_version_file(PackInfo, searchPath2) if rcHome != None: fromFile = rcHome.get_fullname() else: rcRelease = pi.real_version_file(PackInfo, searchPath1) if rcRelease == None: err = "Cannot find a valid pack {}".format(packname) log.error(err) return ResultFileProc(False, [err], [], None) fromFile = rcRelease.get_fullname() # build up the new pack file release_path = "" tmp = os.path.join(tempfile.gettempdir(), "pack_%s" % uuid.uuid4().hex) foundR = foundV = False with open(fromFile, "rt") as fin: with open(tmp, "wt") as fout: for line in fin: if foundR and foundV: fout.write(line) continue m = self.__pat_release.search(line) if m and m.start() == 0: release_path = os.path.join(top_release_path, repo_name) fout.write('base_release = "%s"\n' % release_path) foundR = True else: m = self.__pat_version.search(line) if m and m.start() == 0: fout.write('version = "%s"\n' % version) foundV = True else: m = self.__pat_version_repo.search(line) if m and m.start() == 0: fout.write('version_repo = "%s"\n' % version) foundV = True else: fout.write(line) todolist = BaseFileProc() rcRelease = pi.real_version_file(PackInfo, searchPath1) if rcRelease == None: rcHome.version_up_minor() toFile = rcHome.get_fullname() # repath toFile = toFile.replace(searchPath2[0], searchPath1[0]) if not with_version: x = VersionHelper(toFile) x.unversioned() toFile = x.format() todolist.copy_envifile(tmp, toFile) else: rcRelease.version_up_minor() toFile = rcRelease.get_fullname() if not with_version: x = VersionHelper(toFile) x.unversioned() toFile = x.format() todolist.copy_envifile(tmp, toFile) log.info("Creating new pack from: {} to: {}".format(fromFile, toFile)) todolist.delete_file(tmp) res_copy = todolist.execute_stop_first_failed(run_dry=False, with_log=True) return res_copy
def pack_checkout(self, fromdir, todir, packname, dev_path, repo_name): """Create a packname in user area :param fromdir: (str path) an envi release place ex: BaseEnv.base() :param todir: (str path) an envi user_place ex: BaseEnv.user_home('eric') :param packname: (str) the name of the pack :param dev_path: (str path) top dev user git area ex: /mnt/dev/${USER}/packages (see: $DSKENV/configs_and_packs/envi_info.yml) :param repo_name: (str) dir name of the repo. ex: mgtk-multi-setuptools :returns ResultFileProc: """ if not os.path.isdir(todir): new_user_pack_area = os.path.join(todir, PackInfo.get_label()) FileSystemUtils.ensure_folder_exists( os.path.dirname(new_user_pack_area), permissions=0o775) log.info( "create a user pack area in {}".format(new_user_pack_area)) if not os.path.isdir(todir): return ResultFileProc(False, ["Doesn't exist %s" % todir], [], None) searchPath1 = [fromdir] searchPath2 = [todir] pi = PackInfo(packname) tmp = os.path.join(tempfile.gettempdir(), "pack_%s" % uuid.uuid4().hex) todolist = BaseFileProc() # build up the new pack file rcRelease = pi.real_version_file(PackInfo, searchPath1) if rcRelease != None: toFile = os.path.join(searchPath2[0], pi.get_label(), packname + ".py") fromFile = rcRelease.get_fullname() foundR = foundV = False with open(fromFile, "rt") as fin: with open(tmp, "wt") as fout: for line in fin: if foundR and foundV: fout.write(line) continue m = self.__pat_release.search(line) if m: x = line.split("=")[1] x = x.strip() x = x.split(os.sep)[-1] x = x.replace("'", "") x = x.replace('"', "") source_dev_path = os.path.join(dev_path, x) fout.write("base_release = %r\n" % source_dev_path) foundR = True else: m = self.__pat_version.search(line) if m: fout.write('version = ""\n') foundV = True else: m = self.__pat_version_repo.search(line) if m: fout.write('version_repo = ""\n') foundV = True else: fout.write(line) todolist.copy_envifile(tmp, toFile) todolist.delete_file(tmp) else: # make a blank from dsk.templates.template_envi import repo_pack toFile = os.path.join(searchPath2[0], pi.get_label(), packname + ".py") data = repo_pack.DATA_PACK % { 'rootname': os.path.join(dev_path, repo_name) } with open(tmp, "wt") as fout: fout.write(data) todolist.copy_envifile(tmp, toFile) todolist.delete_file(tmp) res_copy = todolist.execute_stop_first_failed(run_dry=False, with_log=True) return res_copy
def print_info(self, debug=False): if not self.is_valid() or self.start_from_cmds == True: log.error("no app, cannot print anything") return log.info("project Entity %s" % self.get_project_entity()) log.info("user_context %s" % self.get_user_context()) log.info("status %s debug %s" % (self.is_allow('Artist', debug), debug)) log.info("config name %s" % self._app.tank.configuration_name) log.info("config version %s" % self._app.tank.version) log.info("project path %s" % self._app.tank.project_path)
def H_toolInstanciate(widgetApp, editor, widgetNameAction, aname=""): widgetName = "" isNew = False if not isinstance(widgetNameAction, str): widgetN = str(widgetNameAction.text()) isNew = True for i in widgetApp._toolList: if widgetN == widgetApp._toolList[i].name: widgetName = i break else: widgetName = str(widgetNameAction) if not widgetName in list(widgetApp._toolList.keys()): return # reject if unique and already in there if widgetApp._toolList[widgetName].unique == True: if widgetApp._toolList[widgetName].name in widgetApp._docksWidget: log.warning("this widget can only be instantiate once") # let be sure that it's visible then widgetApp._docksWidget[widgetApp._toolList[widgetName].name].show() return widgetApp.setCursor(QtT.QtCore.Qt.WaitCursor) uniqueName = "" # find a unique name if aname == "": uniqueName = get_unique_widget_name( widgetApp._docksWidget, widgetApp._toolList[widgetName].name) else: #uniqueName = widgetApp.getWidgetName(aname) uniqueName = get_unique_widget_name(widgetApp._docksWidget, aname) wclass = widgetApp._toolList[widgetName].get_factory() wclassn = widgetApp._toolList[widgetName].wid_class if wclass == None: log.error("can't load %r" % (widgetName)) traceback.print_exc() widgetApp.setCursor(QtT.QtCore.Qt.ArrowCursor) return cmd = "from dsk.base.widgets.app_dock_widget import DockWidget\n" cmd += widgetApp._toolList[widgetName].str_import() + "\n" cmd += "widgetApp._docksWidget[%r] = DockWidget(widgetApp,%r,%s,False)" % ( uniqueName, uniqueName, wclassn) try: exec(cmd) except: log.error("can't create %r in dock" % (widgetName)) traceback.print_exc() widgetApp.setCursor(QtT.QtCore.Qt.ArrowCursor) return log.info("Creating dockTools %r(%r)" % (uniqueName, widgetName)) widgetApp._docksWidget[uniqueName].setObjectName("D" + uniqueName) widgetApp._docksWidget[uniqueName].setFeatures( QtT.QtWidgets.QDockWidget.DockWidgetMovable | QtT.QtWidgets.QDockWidget.DockWidgetFloatable | QtT.QtWidgets.QDockWidget.DockWidgetClosable) prefArea = QtT.QtCore.Qt.RightDockWidgetArea if isNew == True: upref = widgetApp._toolList[widgetName].pref_place if upref == "L": prefArea = QtT.QtCore.Qt.LeftDockWidgetArea elif upref == 'T': prefArea = QtT.QtCore.Qt.TopDockWidgetArea elif upref == "B": prefArea = QtT.QtCore.Qt.BottomDockWidgetArea widgetApp.addDockWidget(prefArea, widgetApp._docksWidget[uniqueName]) # time for each widget to register there signal widgetApp._docksWidget[uniqueName].registerWidget(editor) msg = MsgFirstTime(widgetApp._docksWidget[uniqueName].getCustomWidget()) widgetApp.sig[confsig.INIT_FIRST_TIME.name].emit(msg) # submenu registration om = widgetApp._toolList[widgetName].optmenu if om != None: widgetApp.addSubOptionMenu(uniqueName, om) widgetApp.setCursor(QtT.QtCore.Qt.ArrowCursor)