def createLockFile(self): """Missing DocString """ # Check if the lock-folder already exists and if not create it if not os.path.isdir(self.lock_folder): creation_status = \ cgruutils.createFolder(self.lock_folder, writeToAll=True) # If the lock-folder does still not exist inform user if creation_status: if self.debug: print("The Lock-Folder: %s" % self.lock_folder) else: print("ERROR: The following Lock-Folder could not get " "created: %s" % self.lock_folder) lock_file = os.path.join(self.lock_folder, self.lock_uuid) the_lock_file = open(lock_file, "w") the_lock_file.close() if not os.path.isfile(lock_file): print("ERROR: The following Lock-File could not get created: %s" % lock_file) return None return lock_file
def __init__(self, scene_name, service='generic', type_='render', debug=False): self.folderPath = None self.debug = debug self.type = type_ self.lock_uuid = str(uuid.uuid1()) self.lock_folder = None self.lock_file = None # Try to get the path to the main-temp-folder self.temp_directory = tempfile.gettempdir() # Get todays and yesterdays date for temp-folder-name and to know which # ones to keep when the delete-old-temp-folder function runs today_time = datetime.datetime.today() yesterday_time = today_time - datetime.timedelta(1) self.today = today_time.strftime("%Y-%m-%d") self.yesterday = yesterday_time.strftime('%Y-%m-%d') # Build the full-temp-path self.folderPath = os.path.join(self.temp_directory, self.type, self.today, service, scene_name) # Check if the temp-folder already exists and if not create it if not os.path.isdir(self.folderPath): creation_status = \ cgruutils.createFolder(self.folderPath, writeToAll=True) # If the temp-folder does still not exist inform user if not creation_status: print("ERROR: The following Temp-Folder could not get " "created: %s" % self.folderPath) # If the temp-directory really exists go on if os.path.isdir(self.folderPath): if self.debug: print("The Temp-Folder: %s" % self.folderPath) # First create a lock-file for the folder self.lock_folder = os.path.join(self.folderPath, ".lock") self.lock_file = self.createLockFile() # And then delete all the old-temp-folders which are not in use # anymore self.deleteOldTempFolders()
def __init__(self, scene_name, service='generic', type_='render', debug=False): self.folderPath = None self.debug = debug self.type = type_ self.lock_uuid = str(uuid.uuid1()) self.lock_folder = None self.lock_file = None # Try to get the path to the main-temp-folder self.temp_directory = tempfile.gettempdir() # Get todays and yesterdays date for temp-folder-name and to know which # ones to keep when the delete-old-temp-folder function runs today_time = datetime.datetime.today() yesterday_time = today_time - datetime.timedelta(1) self.today = today_time.strftime("%Y-%m-%d") self.yesterday = yesterday_time.strftime('%Y-%m-%d') # Build the full-temp-path self.folderPath = os.path.join( self.temp_directory, self.type, self.today, service, scene_name ) # Check if the temp-folder already exists and if not create it if not os.path.isdir(self.folderPath): creation_status = \ cgruutils.createFolder(self.folderPath, writeToAll=True) # If the temp-folder does still not exist inform user if not creation_status: print("ERROR: The following Temp-Folder could not get " "created: %s" % self.folderPath) # If the temp-directory really exists go on if os.path.isdir(self.folderPath): if self.debug: print("The Temp-Folder: %s" % self.folderPath) # First create a lock-file for the folder self.lock_folder = os.path.join(self.folderPath, ".lock") self.lock_file = self.createLockFile() # And then delete all the old-temp-folders which are not in use # anymore self.deleteOldTempFolders()
def __init__( self, variables = VARS, configfiles = None, Verbose = False): self.verbose = Verbose self.Vars = variables self.recursion = False if configfiles is None: self.recursion = True self.Vars['filenames'] = [] self.Vars['platform'] = ['unix'] if sys.platform[:3] == 'win': self.Vars['platform'] = ['windows'] elif sys.platform[:6] == 'darwin': self.Vars['platform'].append('macosx') elif sys.platform[:5] == 'linux': self.Vars['platform'].append('linux') if self.verbose: print('Platform: "%s"' % self.Vars['platform'].join(' ')) self.Vars['HOSTNAME'] = socket.gethostname().lower() cgrulocation = os.getenv('CGRU_LOCATION') if cgrulocation is None or cgrulocation == '': return # Definitions which always must preset: self.Vars['CGRU_LOCATION'] = cgrulocation self.Vars['CGRU_VERSION'] = os.getenv('CGRU_VERSION','') self.Vars['CGRU_PYTHONEXE'] = os.getenv('CGRU_PYTHONEXE','python') self.Vars['CGRU_UPDATE_CMD'] = os.getenv('CGRU_UPDATE_CMD') self.Vars['company'] = 'CGRU' self.Vars['menu_path'] = None self.Vars['tray_icon'] = None self.Vars['icons_path'] = None if sys.platform.find('win') == 0: self.Vars['editor'] = 'notepad "%s"' else: self.Vars['editor'] = 'xterm -e vi "%s"' afroot = os.getenv('AF_ROOT') if afroot is None: afroot = os.path.join( cgrulocation, 'afanasy') self.Vars['AF_ROOT'] = afroot username = os.getenv('CGRU_USERNAME', os.getenv('AF_USERNAME', os.getenv('USER', os.getenv('USERNAME')))) if username == None: username = '******' # cut DOMAIN from username: dpos = username.rfind('/') if dpos == -1: dpos = username.rfind('\\') if dpos != -1: username = username[dpos+1:] username = username.lower() self.Vars['USERNAME'] = username home = os.getenv('HOME', os.getenv('HOMEPATH')) self.Vars['HOME'] = home self.Vars['HOME_CGRU'] = os.path.join( home, '.cgru') self.Vars['config_file_home'] = os.path.join( self.Vars['HOME_CGRU'], 'config.json') if sys.platform.find('win') == 0 or os.geteuid() != 0: cgruutils.createFolder( self.Vars['HOME_CGRU'] ) # Create cgru home config file if not preset checkConfigFile( self.Vars['config_file_home']) configfiles = [] configfiles.append( os.path.join( cgrulocation, 'config_default.json')) configfiles.append( self.Vars['config_file_home']) for filename in configfiles: self.load( filename)
# Copy the scene-file to the temp-directory (copies only when newer then a maybe already existing one) cgruutils.copy_file(scene_file_path, temp_scene_file_path, debug=debug) # Copy now the scene-folders (copies only when newer then a maybe already existing one) folders_to_copy = ['tex'] for this_folder_name in folders_to_copy: source_folder = os.path.join(scene_folder, this_folder_name) temp_folder = os.path.join(temp_directory, this_folder_name) cgruutils.copy_directory(source_folder, temp_folder, debug=debug) # Now create the folder in which always the images get rendered to temp_output_folder = os.path.join(temp_directory, "Output") if not os.path.isdir(temp_output_folder): creation_status = cgruutils.createFolder( temp_output_folder, writeToAll = True) if not creation_status: error_exit( "The Temp-Output-Folder could not get created. So images can not get rendered and script stopped" ) # Create the parameteres to execute and set that it should start with the c4d command and should use the new scene-file parameteres = sys.argv parameteres[0] = "c4d" parameteres[parameteres.index("-render")+1] = temp_scene_file_path output_overwrite = False # If image-output-overwrite is set then redirect it to local Output-Folder try: output_overwrite = parameteres[parameteres.index("-oimage")+1] (oimage_overwrite_folder, oimage_overwrite_filename) = os.path.split(output_overwrite)
def __init__(self, variables=VARS, configfiles=None, Verbose=False): self.verbose = Verbose self.Vars = variables self.recursion = False if configfiles is None: self.recursion = True self.Vars['filenames'] = [] self.Vars['platform'] = ['unix'] if sys.platform[:3] == 'win': self.Vars['platform'] = ['windows'] elif sys.platform[:6] == 'darwin': self.Vars['platform'].append('macosx') elif sys.platform[:5] == 'linux': self.Vars['platform'].append('linux') if self.verbose: print('Platform: "%s"' % self.Vars['platform'].join(' ')) self.Vars['HOSTNAME'] = socket.gethostname().lower() cgrulocation = os.getenv('CGRU_LOCATION') if cgrulocation is None or cgrulocation == '': return # Definitions which always must preset: self.Vars['CGRU_LOCATION'] = cgrulocation self.Vars['CGRU_VERSION'] = os.getenv('CGRU_VERSION', '') self.Vars['CGRU_PYTHONEXE'] = os.getenv('CGRU_PYTHONEXE', 'python') self.Vars['CGRU_UPDATE_CMD'] = os.getenv('CGRU_UPDATE_CMD') self.Vars['company'] = 'CGRU' self.Vars['menu_path'] = None self.Vars['tray_icon'] = None self.Vars['icons_path'] = None if sys.platform.find('win') == 0: self.Vars['editor'] = 'notepad "%s"' else: self.Vars['editor'] = 'xterm -e vi "%s"' afroot = os.getenv('AF_ROOT') if afroot is None: afroot = os.path.join(cgrulocation, 'afanasy') self.Vars['AF_ROOT'] = afroot username = os.getenv( 'CGRU_USERNAME', os.getenv('AF_USERNAME', os.getenv('USER', os.getenv('USERNAME')))) if username == None: username = '******' # cut DOMAIN from username: dpos = username.rfind('/') if dpos == -1: dpos = username.rfind('\\') if dpos != -1: username = username[dpos + 1:] username = username.lower() self.Vars['USERNAME'] = username home = os.getenv('HOME', os.getenv('HOMEPATH')) if home is None: home = username self.Vars['HOME'] = home self.Vars['HOME_CGRU'] = os.path.join(home, '.cgru') self.Vars['config_file_home'] = os.path.join( self.Vars['HOME_CGRU'], 'config.json') if sys.platform.find('win') == 0 or os.geteuid() != 0: cgruutils.createFolder(self.Vars['HOME_CGRU']) # Create cgru home config file if not preset checkConfigFile(self.Vars['config_file_home']) configfiles = [] configfiles.append( os.path.join(cgrulocation, 'config_default.json')) configfiles.append(self.Vars['config_file_home']) for filename in configfiles: self.load(filename)
cgruutils.copy_file(scene_file_path, temp_scene_file_path, debug=debug) # Copy now the scene-folders (copies only when newer then a maybe already # existing one) folders_to_copy = ['tex'] for this_folder_name in folders_to_copy: source_folder = os.path.join(scene_folder, this_folder_name) temp_folder = os.path.join(temp_directory, this_folder_name) cgruutils.copy_directory(source_folder, temp_folder, debug=debug) # Now create the folder in which always the images get rendered to temp_output_folder = os.path.join(temp_directory, "Output") if not os.path.isdir(temp_output_folder): creation_status = cgruutils.createFolder(temp_output_folder, writeToAll=True) if not creation_status: error_exit("The Temp-Output-Folder could not get created. So images " "can not get rendered and script stopped") # Create the parameters to execute and set that it should start with the c4d # command and should use the new scene-file parameters = sys.argv parameters[0] = "c4d" parameters[parameters.index("-render") + 1] = temp_scene_file_path # If image-output-overwrite is set then redirect it to local Output-Folder output_overwrite = False try: