def get_value(self, section, key, cast=str): try: # List in ini are separated with ";". They're also stripped from their spaces if cast == list: value = [v.strip() for v in self.content[section][key].split(";")] # Else we cast it else: value = cast(self.content[section][key]) return value except: # To keep consistency and ease to use for the end user # Logging where the value was expected. # Replacing it to be sure it's still working even after this error. log.notice("Error retrieving value for {} [{}][{}].".format( self.path, section, key, )) # Getting the new value log.notice("Replacing value with : {}".format(serialized[section][key])) # Replacing the config value with a default value self.content[section][key] = serialized[section][key] # Saving the current INI to keep it safe to use self.save() # Returning new value, using this method return self.get_value(section, key, cast)
def create_files(self, dest): """copies all files from the skeleton in the dest dir""" log.debug('creating files.') if self.skel: for skel_file in self.skel.filelist: #full path to source file source_file = os.path.join( os.path.dirname(self.skel.filename), os.path.basename(skel_file) ) log.debug( 'checking for file: ' + source_file ) if len(self.params) != len(self.skel.params): log.error('Incorrect number of arguments; aborting...') paramlist = list() for p in self.skel.params: paramlist.append(p.keys()[0]) log.error('expected: ' + ' '.join(paramlist)) # sys.exit(1) if os.path.exists(source_file): dest_file = os.path.join( dest, self.rep_vars(self.skel, skel_file) ) dest_path = os.path.abspath(dest_file) dest_path = os.path.dirname(dest_path) if not os.path.exists(dest_path): log.notice( 'directory does not exist, ' + 'creating: ' + dest_path ) os.makedirs(dest_path) if not os.path.exists(dest_file): shutil.copyfile(source_file, dest_file) renamed = self.rep_vars_file( self.skel, dest_file ) n_file = dest_file if renamed != dest_file: shutil.move(dest_file, renamed) n_file = renamed log.notice( 'Created file: ' + n_file ) else: log.warning( 'File exists, skipping: ' + skel_file ) else: log.error( 'could not copy file from ' + 'skeleton because it does not exist: ' + source_file ) # sys.exit(1) else: log.debug('no skel file set, aborting...')
"""wrapper function for to_xml, returns object as xml""" return self.to_xml() def save_file(self, filename): """Save file""" xml = self.get_xml() # write to file f = open(filename, "w") f.write(xml) f.close() if __name__ == "__main__": log.notice("Running test cases for Skel...") log.notice("Creating test object...") ts = Skel() log.notice("Attempting to open a file that does not exist...") ts.load_file("this-does-not-exist.xml") ts.name = "sample file" ts.author = "sample author" ts.directive = "samp" ts.language = "C++" ts.add_file("main.cpp") ts.add_file("this should not appear") ts.remove_file("this should not appear") log.notice("Writing test object to file f.xml...") ts.save_file("f.xml")
from obscontroller import ObsController from rocksniffer import Rocksniffer from iniReader import INIReader from time import sleep from logger import log from debug import Debugger # Initializing main objects # Configuration conf = None try: conf = INIReader("config.ini") except FileNotFoundError: log.notice( 'A config.ini file was created. Fill it, then relaunch RocksmithSceneSwitcher.' ) log.notice('Press any key to exit this program.') input() exit(0) debug = Debugger(conf.get_value("Debugging", "debug", int), conf.get_value("Debugging", "log_state_interval", int)) # OBS Web Socket Client / OBS controller abstraction client = ObsController(conf.get_value("OBSWebSocket", "host"), conf.get_value("OBSWebSocket", "port"), conf.get_value("OBSWebSocket", "pass")) sniffer = Rocksniffer( conf.get_value("RockSniffer", "host"), conf.get_value("RockSniffer", "port"), )
if __name__ == '__main__': #test Language obj lang = Language(name='python', alias='py') print lang.name, lang.alias lang.add_directive('proj', '/create/project.xml') print lang.directives l = Languages('skel/language.xml') l.lang('C').add_directive('test','test.xml') l.lang('cpp').add_directive('testcpp', 'testcpp.xml') for lang in l.languages: print lang.name, lang.alias, lang.directives #test load directives log.notice('Attempting to load directives...') l.load_directives('skel') for lang in l.languages: print lang.name, lang.alias, lang.directives log.notice( 'Checking for sample directive: proj/cli in cpp: ' + str(l.lang('cpp').get_directive('proj/cli')) ) # log.notice( # 'Checking for non-existant directive: proj/main in cpp: ' # + str(l.lang('cpp').get_directive('proj/main')) # ) print l.get_directory()