Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# set logging
if args.loglevel:
logmap={
'debug':logging.DEBUG,
'info':logging.INFO,
'warn':logging.WARN,
'error':logging.ERROR
}
tts.logger().setLevel(logmap[args.loglevel])
else:
tts.logger().setLevel(logging.WARN)
# load filesystem values
if args.directory:
self.filesystem = tts.filesystem.FileSystem(os.path.abspath(args.directory))
else:
self.filesystem = tts.get_default_fs()
if (args.parser=='list' or args.parser=='export') and not args.save_type:
# set default
args.save_type = tts.SaveType.workshop
if (args.parser=='config' and args.parser_config=='set' and not args.mod_location and not args.tts_location):
#parser_config.print_usage()
parser_config_set.error("At least one of -m or -t is required.")
rc,message = args.func(args)
if message:
print(message)
sys.exit(rc)
def do_config_validate(self,args):
fs=tts.filesystem.FileSystem(tts_install_path=self.preferences.TTSLocation)
if fs.check_dirs():
return 0,"Configuration validated OK."
else:
return 1,"Configuration failed to validate."
def get_default_fs():
return FileSystem(standard_basepath())
def reload_filesystem(self):
if self.preferences.locationIsUser:
self.filesystem=tts.get_default_fs()
else:
self.filesystem=tts.filesystem.FileSystem(tts_install_path=self.preferences.TTSLocation)
def export(self,export_filename):
log=tts.logger()
log.info("About to export %s to %s" % (self.ident,export_filename))
zfs = tts.filesystem.FileSystem(base_path="")
zipComment = {
"Ver":1,
"Id":self.ident,
"Type":self.save_type.name
}
# TODO: error checking.
with zipfile.ZipFile(export_filename,'w') as zf:
zf.comment=json.dumps(zipComment).encode('utf-8')
log.debug("Writing {} (base {}) to {}".format(self.filename,os.path.basename(self.filename),zfs.get_path_by_type(os.path.basename(self.filename),self.save_type)))
zf.write(self.filename,zfs.get_path_by_type(os.path.basename(self.filename),self.save_type))
for url in self.models:
log.debug("Writing {} to {}".format(url.location,zfs.get_model_path(os.path.basename(url.location))))
zf.write(url.location,zfs.get_model_path(os.path.basename(url.location)))
for url in self.images:
log.debug("Writing {} to {}".format(url.location,zfs.get_model_path(os.path.basename(url.location))))