def __init__(self, parent): """ Load from userhome/.xnat.cfg :param parent: """ super(OPEXUploaderGUI, self).__init__(parent) self.Bind(wx.EVT_CLOSE, self.OnExit) self.SetTitle("OPEX Uploader App") self.SetPosition(wx.Point(100, 100)) self.SetSize((700, 700)) self.configfile = join(expanduser('~'), '.xnat.cfg') self.resource_dir = findResourceDir() self.configdb = join(self.resource_dir, 'opexconfig.db') self.loaded = self.__loadConfig() self.runoptions = self.__loadOptions() self.opexid = False self.subjectchars = 6 if self.loaded: self.chOptions.SetItems(sorted(self.runoptions.keys())) self.dbedit.AppendItems(self.config.keys()) # # DISPLAY OUTPUT IN WINDOW as stdout sys.stdout = LogOutput(self.tcResults) # Update status bar from Thread EVT_RESULT(self, self.__statusoutput) self.m_statusBar1.SetStatusText( 'Welcome to the Uploader! Help is available from the Menu') self.Show()
def OnHelp(self, e): """ Show the User Help Guide :param e: :return: """ resource_dir = findResourceDir() projdir = dirname(resource_dir) local_readme_url = join(projdir, 'README.md') readme_url = 'https://raw.githubusercontent.com/QBI-Software/OPEXUploader/master/README.md' http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) mdfile = http.request('GET', readme_url) # Write locally if sys.platform == 'win32': flag = 'wb' else: flag = 'w' with open(local_readme_url, flag) as output: output.write(mdfile.data) help_page = join(resource_dir, 'HELP.html') md = markdown.Markdown() md.convertFile(local_readme_url, help_page) # Load to dialog dlg = dlgHelp(self) dlg.m_htmlWin1.LoadPage(help_page) dlg.Show()
def __loadopexfile(self): """ Load experiment info from opex.csv :return: """ try: self.resource_dir = findResourceDir() opexfile = join(self.resource_dir, 'opex.csv') opex = pandas.read_csv(opexfile) msg = 'OPEX Resources loaded: %s from %s' % (not opex.empty, opexfile) logging.info(msg) return opex except Exception as e: msg = 'OPEX Resources NOT loaded: %s' % (e.args[0]) logging.error(msg) raise IOError(e)
def __init__(self, subjects=None): """ List of subjects from XNAT as collection :param subjects: :param csvfile: spreadsheet export from OPEX subjects tab (with counts) """ self.subjects = subjects self.subjectids = None self.data = None self.minmth = 0 self.maxmth = 12 configdb = join(findResourceDir(), 'opexconfig.db') if not access(configdb, R_OK): raise IOError('Cannot find config database') self.dbi = DBI(configdb) self.expts = self.dbi.getExpts() self.xnat = None self.__loaddata()
def __init__(self, datafile=None, sheet=0, skiplines=0, header=None, etype=None): msg = 'DataParser: datafile=%s sheet=%s skiplines=%s header=%s etype=%s' % ( datafile, str(sheet), str(skiplines), str(header), str(etype)) print(msg) logging.info(msg) self.datafile = datafile # full pathname to data file self.resource_dir = findResourceDir() configdb = join(self.resource_dir, 'opexconfig.db') if not access(configdb, R_OK): print(configdb) raise IOError('Cannot find config database {}'.format(configdb)) try: self.dbi = DBI(configdb) self.etype = etype if etype is not None: self.info = self.dbi.getInfo(etype) self.fields = self.dbi.getFields(etype) else: self.info = None self.fields = None self.subjects = None self.incorrect = self.dbi.getIDs() if self.datafile is not None and len(self.datafile) > 0: (bname, extn) = splitext(basename(self.datafile)) self.ftype = extn # extension - xlsx or csv self.sheet = sheet self.skiplines = skiplines self.header = header self._loadData() except Exception as e: raise e
def __init__(self, parent): super(IdsDialog, self).__init__(parent) self.resource_dir = findResourceDir() self.idfile = join(self.resource_dir, 'incorrectIds.csv') self.iddb = join(self.resource_dir, 'opexconfig.db') self.__loadData()
def test_FieldsDir(self): resourcedir = findResourceDir() expected = os.path.join(resourcedir, 'fields') print('Testing: ', expected) self.assertTrue(os.path.exists(expected))
def test_ResourceDir(self): resourcedir = findResourceDir() print('Resource dir: ', resourcedir) expected = 'resources' self.assertEqual(os.path.basename(resourcedir), expected)
def setUp(self): self.resourcedir = findResourceDir() configdb = join(self.resourcedir, 'opexconfig_test.db') self.dbi = DBI(configdb) self.dbi.getconn()