def pushMaya( db=None, doc_id="", description="", item=None, screenshot="", msgbar=False, progressbar=False, selection=False, rename=True, extension=".mb", ): if not (screenshot == ""): fname = os.path.join("/tmp", "%s%s" % (utils.hashTime(), extension)) fname = saveFile(fname, selection, msgbar, doc_id) if fname: destination = core.push(db, doc_id, fname, description, progressbar, msgbar, rename) core.transfer(screenshot, destination, doc_id) source = os.path.join(destination, doc_id + extension) print "pushMaya():", source assetExport(source) if msgbar: msgbar("Done") return destination return False else: msgbar("Please make a screenshot")
def pushDir (db = "", doc_id = "", path = list(), description = "", vtype = "review"): """ This function copy the desired file from local workspace to repository. :param db: the database :type db: Database :param doc_id: The asset code :type doc_id: str :param path: directory or The list of directories to push :type path: str/list of str :param description: This is the description of the push :type description: str :param vtype: Version type *trial/stock* :type vtype: str :returns: str -- Return the published directory **Example:** >>> db = utils.getDb() >>> pushDir ( db = db, doc_id = "bls_chr_belanus_mod_main", >>> path = "/homeworks/users/jdoe/projects/bls/chr/belanus/tex/main/directory_to_push", >>> description = "This is a publish" ) """ # Make sure vtype exists if utils.checkVersionType (vtype) : return False # check if the source file exists in the repository if not os.path.exists (path) : print "pushDir(): %s doesn't exist"%path return False # Get root destination directory to push files dst_dir=getPathFromId (doc_id = doc_id, vtype = vtype) # Get temporary destination directory to push files tmp_dir=os.path.join (dst_dir, utils.hashTime ()) os.makedirs (tmp_dir) # Copy all the files in the destination directory files_attr=list () file_list=os.listdir (path) for src in file_list : # file space in case we need to publish directories """ path_src=os.path.join (path, src) dst=os.path.join (tmp_dir, src) if os.path.isfile (path_src): print "pushDir(): copying file %s "%src shutil.copy (path_src, dst) elif os.path.isdir (path_src): print "pushDir(): copying directory %s "%src shutil.copytree (path_src, dst) # Store the files names in a list to avoid to call the database for each source file files_attr.append (src) # Get latest version number because somebody may push a new version during the process doc=db [ doc_id ] ver_attr=getVersions (db = db, doc_id = doc_id, vtype = vtype) ver=len (ver_attr)+1 path_attr=os.path.join (dst_dir, "%03d"%ver) repo=os.path.expandvars (path_attr) # Rename the temp dir os.rename (tmp_dir, repo) os.chmod (repo, 0555) # Create the new version data for the "versions" document's attribute fileinfo={ "creator" : os.getenv ("USER"), "created" : time.time(), "description" : description , "path" : path_attr , "files" : files_attr } # Append the data into the document version attribute copy ver_attr [ ver ]=fileinfo # Replace the original "versions" attribute by our modified version doc [ vtype ]=ver_attr # Push the info into the db db [ doc_id ]=doc # print published file for the user for fil in files_attr: print os.path.join (repo , fil) # Return the published directory return repo
def push (db = "", doc_id = "", path = list(), description = "", progressbar = False, msgbar = False, rename = True, vtype = "review"): """ This function copy the desired file from local workspace to repository. :param db: the database :type db: Database :param doc_id: The asset code :type doc_id: str :param path: The list of files to push :type path: str/list of str :param description: This is the description of the push :type description: str :param progressbar: The pyside progress bar :type progressbar: PySide progressbar :param msg: The pyside message bar :type progressbar: PySide messagebar :param rename: Rename the file (default True) :type rename: bool -- if True rename the file(s) :param vtype: Version type *trial/stock* :type vtype: str :returns: str -- Return the published directory **Example:** >>> db = utils.getDb() >>> push ( db = db, doc_id = "bls_chr_belanus_mod_main", >>> path = "/homeworks/users/jdoe/projects/bls/chr/belanus/mod/main/file_to_push.mb", >>> description = "this is a modeling version of belanus" ) """ # Make sure vtype exists if utils.checkVersionType (vtype) : return False # TODO: Check push for auto screenshot publish # Check the path type is a list if type (path)==str : path=list ([ path ]) # check if the source file exists in the repository file_list=list () for src in path : if os.path.exists (src) : file_list.append (src) else: print "Warning: %s doesn't exist"%src # Get root destination directory to push files dst_dir=getPathFromId (doc_id, vtype = vtype) # Get temporary destination directory to push files tmp_dir=os.path.join (dst_dir, utils.hashTime ()) # Create temporary directory if not os.path.exists (tmp_dir): os.makedirs (tmp_dir) # Copy all the files in the destination directory progress_value=0 progress_step=100.0/len (file_list) files_attr=list () wspace=getPathFromId (doc_id = doc_id, local = True, vtype = vtype) # Iterate over all the provided source files for src in file_list : # Get file dir src_dir=os.path.dirname (src) # file space in case we need to publish directories file_space=src_dir.replace (wspace, "") file_name=os.path.join (file_space, os.path.basename (src)) # Get extension(s) ,UDIMs and frames are commonly separated with this char file_ext="."+file_name.split (".")[-1] # Get screenshot file screenshot=False screenshot_exts=[ ".jpg", ".jpeg", ".png" ] screenshot_ext="" for ext in screenshot_exts : screenpath=file_name+ext screenpath=os.path.join (src_dir, screenpath) if os.path.exists (screenpath) : screenshot_ext=ext screenshot=screenpath break else : screenpath=screenpath.replace ("."+file_ext, ext) if screenpath!=file_name : if os.path.exists (screenpath) : screenshot_ext=ext screenshot=screenpath # Creating the full filename if rename: dst_file=doc_id+file_ext dst_screenshot=doc_id+screenshot_ext else: dst_file=file_name dst_screenshot=screenshot if dst_file [0]==os.sep : dst_file=dst_file [1:] tmp_file=os.path.join (tmp_dir, dst_file) # Store the files names in a list to avoid to call the database for each source file files_attr.append (dst_file) # Copy files to temporary directory shutil.copy (src, tmp_file) # Copy screenshot to temporary directory if screenshot : if dst_screenshot [0]==os.sep : dst_screenshot=dst_screenshot [1:] tmp_screenshot=os.path.join (tmp_dir, dst_screenshot) shutil.copy (screenshot, tmp_screenshot) # Set progress value progress_value+=progress_step if progressbar : progressbar.setProperty ("value", progress_value) else : print (str (progress_value)+"%") if msgbar : msgbar (dst_file) # Get latest version doc=db [ doc_id ] ver_attr=getVersions (db, doc_id, vtype = vtype) ver=len (ver_attr)+1 path_attr=os.path.join (dst_dir, "%03d"%ver) repo=os.path.expandvars (path_attr) # Rename the temp dir os.rename (tmp_dir, repo) # TODO:Replace os.system ( "chmod -R 555 %s" % repo ) by python function os.system ("chmod -R 555 %s"%repo) # Create the new version data for the "versions" document's attribute fileinfo={ "creator" : os.getenv ("USER"), "created" : time.time(), "description" : description , "path" : path_attr , "files" : files_attr, "release" : list() } # Check status status=doc ["status"] if status["tec"]=="ns": status["tec"]="wip" doc ["status"]=status # Append the data into the document version attribute copy ver_attr [ ver ]=fileinfo # Replace the original "versions" attribute by our modified version doc [ vtype ]=ver_attr # Push the info into the db db [ doc_id ]=doc # print published file for the user for fil in files_attr: print os.path.join (repo , fil) # Return the published directory return repo
def screenshotClicked(self): self.screenshot = doScreenshot(os.path.join("/tmp", "%s.jpg" % utils.hashTime())) self.labelImage.setPixmap(self.screenshot)