Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def download_all(self):
successful=True
save_type={1:tts.SaveType.workshop,
2:tts.SaveType.save,
3:tts.SaveType.chest}[self.download_sb.save_type.get()]
for ident in self.download_sb.file_store.values():
successful = tts.download_file(self.filesystem,ident,save_type)
if not successful:
break
if successful:
messagebox.showinfo("TTS Manager","All files downloaded successfully.")
else:
messagebox.showinfo("TTS Manager","Some downloads failed (see log).")
If an id is provided, then this will list the contents of that modules.
''')
group_list=parser_list.add_mutually_exclusive_group()
group_list.add_argument("-w","--workshop",action="store_const",metavar='save_type',dest='save_type',const=tts.SaveType.workshop,help="List workshop files (the default).")
group_list.add_argument("-s","--save",action="store_const",metavar='save_type',dest='save_type',const=tts.SaveType.save,help="List saves.")
group_list.add_argument("-c","--chest",action="store_const",metavar='save_type',dest='save_type',const=tts.SaveType.chest,help="List chest files.")
parser_list.add_argument("id",nargs='?',help="ID of specific mod to list details of.")
parser_list.set_defaults(func=self.do_list)
# export command
parser_export = subparsers.add_parser('export',help="Export a mod.",description='Export a mod in a format suitible for later import.')
group_export=parser_export.add_mutually_exclusive_group()
group_export.add_argument("-w","--workshop",action="store_const",dest='save_type',metavar='save_type',const=tts.SaveType.workshop,help="ID is of workshop file (the default).")
group_export.add_argument("-s","--save",action="store_const",dest='save_type',metavar='save_type',const=tts.SaveType.save,help="ID is of savegame file.")
group_export.add_argument("-c","--chest",action="store_const",dest='save_type',metavar='save_type',const=tts.SaveType.chest,help="ID is of chest file.")
parser_export.add_argument("id",help="ID of mod/name of savegame to export.")
parser_export.add_argument("-o","--output",help="Location/file to export to.")
parser_export.add_argument("-f","--force",action="store_true",help="Force creation of export file.")
parser_export.add_argument("-d","--download",action="store_true",help="Attempt to download missing cache files. (EXPERIMENTAL)")
parser_export.set_defaults(func=self.do_export)
# import command
parser_import = subparsers.add_parser('import',help="Import a mod.",description="Import an previously exported mod.")
parser_import.add_argument("file",help="Mod pak file to import.")
parser_import.set_defaults(func=self.do_import)
# download command
parser_download = subparsers.add_parser('download',help='Download mod files.',description='Attempt to download any missing files for an installed mod.')
group_download=parser_download.add_mutually_exclusive_group()
group_download.add_argument("-w","--workshop",action="store_const",dest='save_type',metavar='save_type',const=tts.SaveType.workshop,help="ID is of workshop file.")
group_download.add_argument("-s","--save",action="store_const",dest='save_type',metavar='save_type',const=tts.SaveType.save,help="ID is of savegame file.")
self.save_type=Tk.IntVar()
self.save_type.set(int(tts.SaveType.workshop))
ttk.Radiobutton(srcFrame,
text="Workshop",
variable=self.save_type,
value=int(tts.SaveType.workshop),
command=self.list_command).pack(side=Tk.LEFT)
ttk.Radiobutton(srcFrame,
text="Save",
variable=self.save_type,
value=int(tts.SaveType.save),
command=self.list_command).pack(side=Tk.LEFT)
ttk.Radiobutton(srcFrame,
text="Chest",
variable=self.save_type,
value=int(tts.SaveType.chest),
command=self.list_command).pack(side=Tk.LEFT)
scrollFrame=ttk.Frame(master)
scrollFrame.pack(expand=1,fill=Tk.BOTH)
ttk.Label(scrollFrame,text="Files found:").pack()
foundBar=ttk.Scrollbar(scrollFrame,orient=Tk.VERTICAL)
self.file_list=Tk.Listbox(scrollFrame,yscrollcommand=foundBar.set)
foundBar.config(command=self.file_list.yview)
foundBar.pack(side=Tk.RIGHT,fill=Tk.Y)
self.file_list.pack(side=Tk.LEFT,fill=Tk.BOTH,expand=Tk.Y)
statusFrame=ttk.Frame(master)
statusFrame.pack(expand=Tk.Y,fill=Tk.BOTH)
self.status_label=ttk.Label(statusFrame)
self.status_label.pack(fill=Tk.BOTH,expand=Tk.Y)
self.file_list_current = None
self.poll_file_list()
def get_json_filename_type(self,basename):
if os.path.isfile(os.path.join(self._workshop,basename+'.json')):
return tts.SaveType.workshop
if os.path.isfile(os.path.join(self._saves,basename+'.json')):
return tts.SaveType.save
if os.path.isfile(os.path.join(self._chest,basename+'.json')):
return tts.SaveType.chest
# TODO: error handling here
return None
self.save_type=Tk.IntVar()
self.save_type.set(int(tts.SaveType.workshop))
ttk.Radiobutton(frame,
text="Workshop",
variable=self.save_type,
value=int(tts.SaveType.workshop),
command=self.list_command).grid(row=0,column=1)
ttk.Radiobutton(frame,
text="Save",
variable=self.save_type,
value=int(tts.SaveType.save),
command=self.list_command).grid(row=0,column=2)
ttk.Radiobutton(frame,
text="Chest",
variable=self.save_type,
value=int(tts.SaveType.chest),
command=self.list_command).grid(row=0,column=3)
fl_frame=ttk.Frame(frame)
fl_frame.grid(row=1,columnspan=4,sticky=Tk.N+Tk.S+Tk.E+Tk.W)
ttk.Label(fl_frame,text="Files found:").pack()
foundBar=ttk.Scrollbar(fl_frame,orient=Tk.VERTICAL)
self.file_list_box=Tk.Listbox(fl_frame,yscrollcommand=foundBar.set)
foundBar.config(command=self.file_list_box.yview)
foundBar.pack(side=Tk.RIGHT,fill=Tk.Y)
self.file_list_box.pack(side=Tk.LEFT,fill=Tk.BOTH,expand=Tk.Y)
self.file_list_box.config(state=Tk.DISABLED)
self.downloadButton=ttk.Button(frame,
text="Download",
command=self.download,
state=Tk.DISABLED)
self.downloadButton.grid(row=2,column=0)
def get_dir_by_type(self,save_type):
st={
tts.SaveType.workshop:self._workshop,
tts.SaveType.save:self._saves,
tts.SaveType.chest:self._chest
}
return st[save_type]