def on_unpack(self, event): dlg = wx.FileDialog( None, message = "choose txt file to unpack", defaultDir=self.WD, defaultFile="", style=wx.OPEN #| wx.CHANGE_DIR ) if dlg.ShowModal() == wx.ID_OK: FILE = dlg.GetPath() input_dir, f = os.path.split(FILE) else: return False outstring="download_magic.py -f {} -WD {} -ID {}".format(f, self.WD, input_dir) # run as module: print "-I- running python script:\n %s"%(outstring) wait = wx.BusyInfo("Please wait, working...") ex = None try: if ipmag.download_magic(f, self.WD, input_dir, overwrite=True): text = "Successfully ran download_magic.py program.\nMagIC files were saved in your working directory.\nSee Terminal/Command Prompt for details." else: text = "Something went wrong. Make sure you chose a valid file downloaded from the MagIC database and try again." except Exception as ex: text = "Something went wrong. Make sure you chose a valid file downloaded from the MagIC database and try again." del wait dlg = wx.MessageDialog(self, caption="Saved", message=text, style=wx.OK) result = dlg.ShowModal() if result == wx.ID_OK: dlg.Destroy() if ex: raise(ex)
def main(): """ NAME download_magic.py DESCRIPTION unpacks a magic formatted smartbook .txt file from the MagIC database into the tab delimited MagIC format txt files for use with the MagIC-Py programs. SYNTAX download_magic.py command line options] INPUT takes either the upload.txt file created by upload_magic.py or the file exported by the MagIC v2.2 console software (downloaded from the MagIC database or output by the Console on your PC). OPTIONS -h prints help message and quits -i allows interactive entry of filename -f FILE specifies input file name -O do not overwrite duplicate Location_* directories while downloading """ if '-h' in sys.argv: print main.__doc__ sys.exit() # interactive entry if '-i' in sys.argv: infile=raw_input("Magic txt file for unpacking? ") dir_path = '.' input_dir_path = '.' # non-interactive else: dataframe = extractor.command_line_dataframe([['O', False, True]]) checked_args = extractor.extract_and_check_args(sys.argv, dataframe) infile, dir_path, input_dir_path, overwrite = extractor.get_vars(['f', 'WD', 'ID', 'O'], checked_args) ipmag.download_magic(infile, dir_path, input_dir_path, overwrite)