Exemplo n.º 1
0
 def readConfig(self):
     file = self.cfile.get()
     config = spiderConfig.readXMLConfig(file)
     if config:
         GB.C = config
         GG.sysprefs.configFile = file
         self.updateListbox()
Exemplo n.º 2
0
 def readConfig(self):
     file = self.cfile.get()
     config = spiderConfig.readXMLConfig(file)
     if config:
         GB.C = config
         GG.sysprefs.configFile = file
         self.updateListbox()
Exemplo n.º 3
0
def projOpen(filename=None):
    if filename == None:
        filename = askfilename()
    if filename == "":
        return

    # if it's a path, try to change to the directory with the project file
    projpath = None
    if os.sep in filename:
        projpath, filename = os.path.split(filename)
        if not chdir(projpath):
            txt = "projOpen: Unable to change to %s" % projpath
            print txt
            return

    #  set GB.DB to project file (spiderClasses.ProjectDatabase)
    GB.DB = spiderClasses.ProjectDatabase(filename=filename)

    if not hasDatabase():
        GB.errstream("unable to open project file %s" % filename)
        return

    # obtain project, runlist, config from the project file (database)
    project = GB.DB.get('Project')

    if project:
        GB.P = project

        # make sure database has correct project filename
        cwd = os.getcwd()
        if cwd in GB.P.projdir or GB.P.projdir in cwd:
            GB.P.projdir = cwd
        else:
            GB.outsream("Project directory is no longer %s?\n" % GB.P.projdir)
            if os.path.exists(filename):
                GB.outsream("Changing project directory to: %s\n" % cwd)
                GB.P.projdir = cwd
            else:
                return

        if not remoteProjectPath(GB.P.projdir, projpath):
            GB.errstream("unable to find project directory")
            return

        GB.P.RunList = GB.DB.RunList()  # compute runlist from the projfile

        config = GB.DB.get('Config')
        if config:
            GB.C = config
        else:
            if GB.P.config != "" and os.path.exists(GB.P.config):
                config = spiderConfig.readXMLConfig(GB.P.config)
                if not config:
                    GB.errstream(
                        "spiderProj.projOpen: Unable to load configuration.")
                else:
                    GB.C = config

        projfile = os.path.join(GB.P.projdir, GB.P.projfile)
        GB.DB.filename = projfile

    else:
        displayError(filename + " doesn't appear to contain a valid project.")
        return

    if not projSet():
        GB.outstream('Project not loaded')
        return

    GB.outstream("\nProject: %s, ID: %s\n" % (GB.P.title, GB.P.ID))
    prjtxt = "%s opened " % (os.path.join(GB.P.projdir, GB.P.projfile))
    prjtxt = prjtxt + time.asctime(time.localtime(time.time()))
    GB.outstream(prjtxt)
    getParms()  # load GB.Parameters

    if hasProject() and hasConfig():
        updateMainMenus()
        # if there's a filenums file, load it into File Numbers Entry
        if GG.sysprefs.filenumFile.strip() != "":
            filenumfile = os.path.join(GB.P.projdir, GG.sysprefs.filenumFile)
            a = spiderFilenums.openFileNumbers(filenumfile)
            if a != []:
                fn = spiderFilenums.range2string(spiderFilenums.list2range(a))
                GG.disp_fnums.set(fn)
Exemplo n.º 4
0
    def readEntries(self):
        # 1) check entries for legal values
        ProjID = self.epid.get().strip()
        name = self.ename.get().strip()
        projfile = self.efile.get().strip()
        ext = self.eext.get().strip()
        if len(ext) > 0 and ext[0] == '.' and len(ext) > 1:
            ext = ext[1:]
        projdir = self.edir.get().strip()
        host = self.ehost.get().strip()

        config = self.ecfg.get().strip()
        config = os.path.abspath(config)
        configpath, configfile = os.path.split(config)
        if configpath == os.getcwd():
            CONFIG_IN_CURRENT_DIR = 1
        else:
            CONFIG_IN_CURRENT_DIR = 0

        if name == '' or projfile == '' or ext == '' or projdir == '':
            displayError('Please fill in all the blanks', 'Error')
            self.w.lift()
            return
        elif len(ext) != 3:
            displayError('File extension must\nbe 3 letters long', 'Error')
            self.w.lift()
            return

        # 2) create the project directory, if it doesn't exists
        if not os.path.exists(projdir):
            if askOKorCancel("Create %s?" % (projdir),
                             projdir + " does not exist"):
                if not makeDirectory(projdir):
                    displayError('Unable to access ' + projdir, 'Error')
                    self.w.lift()
                    return
            else:
                return

        killWindow(self.w)

        if not hasProject():
            GB.P = spiderClasses.SpiderProject(id=ProjID)

        projdir = truepath(projdir)
        projfile = truepath(projfile)
        projdir, projext = os.path.splitext(
            projdir)  # no extension on project file
        config = truepath(config)
        chdir(projdir)

        # 3) set project attributes
        GB.P.ID = ProjID
        GB.P.title = name
        GB.P.projfile = os.path.basename(projfile)
        GB.P.dataext = ext
        GB.P.projdir = projdir
        GB.P.host = host
        GB.P.config = config

        # 4) read config.xml file, put config in GB.C, write to local directory
        if config != "":
            if not os.path.exists(config):
                config = os.path.join(GG.sysprefs.configdir, config)
                if not os.path.exists(config):
                    displayError("Unable to find %s" % config)
                    GB.errstream("spiderProj.projEntries: unable to find %s" %
                                 config)
                    return
            c = spiderConfig.readXMLConfig(config)
            if c != 0:
                GB.C = c
                local = os.path.join(projdir, os.path.basename(config))
                if not CONFIG_IN_CURRENT_DIR:
                    GB.C.save2xml(local)
                GB.P.config = local
                GG.sysprefs.configFile = os.path.basename(config)
            else:
                GB.errstream(
                    "spiderProj.projEntries: unable to process config file")

        # 5) copy batch files to project directories
        loadbatch = self.loadvar.get()
        if isCurrentDirectory(GB.C.path):  # checks <location> tags
            loadbatch = 0
        if loadbatch:
            result = loadProject()
            if result == 0:
                GB.errstream("loadProject: error loading project")
                return

        # 6) set GB.DB to project file
        projfile = os.path.join(projdir, projfile)
        GB.DB = spiderClasses.ProjectDatabase(filename=projfile, new=1)

        if not hasDatabase():
            GG.topwindow.bell()
            GB.errstream("Unable to create a project file", 'red')
            return

        GB.DB.put('Project', GB.P)
        GB.DB.put('Config', GB.C)

        # 7) sets various graphical objects in Main window, save project
        projSet()
        projSave()

        # 8) Parameter file:
        #    First, see if config specifies 'no parameters'
        if hasConfig('useParameterFile') and GB.C.useParameterFile != 0:
            pass
        else:
            return
        # For a new project, see if Config had default parameters
        if self.mode == 'new' and hasattr(GB.C, 'parms'):
            # GB.C.parms will only be set if config.xml had a <Parameter> section
            parmdict = spiderParam.readParamTextfile(parmlist=GB.C.parms)
            if parmdict != None and len(parmdict) > 0:
                GB.outstream("Using default parameter list from %s" % config)
                spiderParam.presentParmForm(parmdict)
                return

        # if the parameter file exists, read it and present form
        parmfile = os.path.join(projdir, GG.sysprefs.paramFile)
        if os.path.exists(parmfile):
            spiderParam.readParmFile(filename=parmfile)
        # otherwise prompt user to create new one
        else:
            spiderParam.parmNew(defaultfile=parmfile)
Exemplo n.º 5
0
def projOpen(filename=None):
    if filename == None:
        filename = askfilename()
    if filename == "":
        return

    # if it's a path, try to change to the directory with the project file
    projpath = None
    if os.sep in filename:
        projpath, filename = os.path.split(filename)
        if not chdir(projpath):
            txt = "projOpen: Unable to change to %s" % projpath
            print txt
            return

    #  set GB.DB to project file (spiderClasses.ProjectDatabase)
    GB.DB = spiderClasses.ProjectDatabase(filename=filename)

    if not hasDatabase():
        GB.errstream("unable to open project file %s" % filename)
        return

    # obtain project, runlist, config from the project file (database)
    project = GB.DB.get('Project')

    if project:
        GB.P = project

        # make sure database has correct project filename 
        cwd = os.getcwd()
        if cwd in GB.P.projdir or GB.P.projdir in cwd:
            GB.P.projdir = cwd
        else:
            GB.outsream("Project directory is no longer %s?\n" % GB.P.projdir)
            if os.path.exists(filename):
                GB.outsream("Changing project directory to: %s\n" % cwd)
                GB.P.projdir = cwd
            else:
                return

        if not remoteProjectPath(GB.P.projdir, projpath):
            GB.errstream("unable to find project directory")
            return
        
        GB.P.RunList = GB.DB.RunList() # compute runlist from the projfile

        config = GB.DB.get('Config')        
        if config:
            GB.C = config
        else:
            if GB.P.config != "" and os.path.exists(GB.P.config):
                config = spiderConfig.readXMLConfig(GB.P.config)
                if not config:
                    GB.errstream("spiderProj.projOpen: Unable to load configuration.")
                else:
                    GB.C = config
                    
        projfile = os.path.join(GB.P.projdir,GB.P.projfile)
        GB.DB.filename = projfile

    else:
        displayError(filename + " doesn't appear to contain a valid project.")
        return

    if not projSet():
        GB.outstream('Project not loaded')
        return
    
    GB.outstream("\nProject: %s, ID: %s\n" % (GB.P.title,GB.P.ID))
    prjtxt = "%s opened " % (os.path.join(GB.P.projdir,GB.P.projfile))
    prjtxt = prjtxt + time.asctime(time.localtime(time.time()))
    GB.outstream(prjtxt)
    getParms()   # load GB.Parameters
    
    if hasProject() and hasConfig():
        updateMainMenus()
        # if there's a filenums file, load it into File Numbers Entry
        if GG.sysprefs.filenumFile.strip() != "":
            filenumfile = os.path.join(GB.P.projdir, GG.sysprefs.filenumFile)
            a = spiderFilenums.openFileNumbers(filenumfile)
            if a != []:
                fn = spiderFilenums.range2string(spiderFilenums.list2range(a))
                GG.disp_fnums.set(fn)
Exemplo n.º 6
0
    def readEntries(self):
        # 1) check entries for legal values
        ProjID = self.epid.get().strip()
        name = self.ename.get().strip()
        projfile = self.efile.get().strip()
        ext  = self.eext.get().strip()
        if len(ext) > 0 and ext[0] == '.' and len(ext) > 1:
            ext = ext[1:]
        projdir  = self.edir.get().strip()
        host = self.ehost.get().strip()
        
        config = self.ecfg.get().strip()
        config = os.path.abspath(config)
        configpath,configfile = os.path.split(config)
        if configpath == os.getcwd():
            CONFIG_IN_CURRENT_DIR = 1
        else:
            CONFIG_IN_CURRENT_DIR = 0
        
        if name == '' or projfile == '' or ext == '' or projdir == '':
            displayError('Please fill in all the blanks','Error')
            self.w.lift()
            return
        elif len(ext) != 3:
            displayError('File extension must\nbe 3 letters long','Error')
            self.w.lift()
            return

        # 2) create the project directory, if it doesn't exists
        if not os.path.exists(projdir):
            if askOKorCancel("Create %s?" % (projdir),projdir + " does not exist"):
                if not makeDirectory(projdir):
                    displayError('Unable to access ' + projdir,'Error')
                    self.w.lift()
                    return
            else:
                return
            
        killWindow(self.w)

        if not hasProject():
            GB.P = spiderClasses.SpiderProject(id=ProjID)
            
        projdir = truepath(projdir)
        projfile = truepath(projfile)
        projdir, projext = os.path.splitext(projdir)  # no extension on project file
        config = truepath(config)
        chdir(projdir)

        # 3) set project attributes
        GB.P.ID = ProjID
        GB.P.title = name
        GB.P.projfile = os.path.basename(projfile)
        GB.P.dataext = ext
        GB.P.projdir  = projdir
        GB.P.host = host
        GB.P.config = config

        # 4) read config.xml file, put config in GB.C, write to local directory
        if config != "":
            if not os.path.exists(config):
                config = os.path.join(GG.sysprefs.configdir, config)
                if not os.path.exists(config):
                    displayError("Unable to find %s" % config)
                    GB.errstream("spiderProj.projEntries: unable to find %s" % config)
                    return
            c = spiderConfig.readXMLConfig(config)
            if c != 0:
                GB.C = c
                local = os.path.join(projdir, os.path.basename(config))
                if not CONFIG_IN_CURRENT_DIR:
                    GB.C.save2xml(local)
                GB.P.config = local
                GG.sysprefs.configFile = os.path.basename(config)
            else:
                GB.errstream("spiderProj.projEntries: unable to process config file")
     
        # 5) copy batch files to project directories
        loadbatch = self.loadvar.get()
        if isCurrentDirectory(GB.C.path):  # checks <location> tags
            loadbatch = 0
        if loadbatch:
            result = loadProject()
            if result == 0:
                GB.errstream("loadProject: error loading project")
                return

        # 6) set GB.DB to project file
        projfile = os.path.join(projdir,projfile)
        GB.DB = spiderClasses.ProjectDatabase(filename=projfile, new=1)
    
        if not hasDatabase():
            GG.topwindow.bell()
            GB.errstream("Unable to create a project file", 'red')
            return

        GB.DB.put('Project', GB.P)
        GB.DB.put('Config', GB.C)

        # 7) sets various graphical objects in Main window, save project
        projSet()
        projSave()
        
        # 8) Parameter file:
        #    First, see if config specifies 'no parameters'
        if hasConfig('useParameterFile') and GB.C.useParameterFile != 0:
            pass
        else:
            return
        # For a new project, see if Config had default parameters
        if self.mode == 'new' and hasattr(GB.C, 'parms'):
            # GB.C.parms will only be set if config.xml had a <Parameter> section
            parmdict = spiderParam.readParamTextfile(parmlist=GB.C.parms)
            if parmdict != None and len(parmdict) > 0:
                GB.outstream("Using default parameter list from %s" % config)
                spiderParam.presentParmForm(parmdict)
                return
                
        # if the parameter file exists, read it and present form
        parmfile = os.path.join(projdir,GG.sysprefs.paramFile)
        if os.path.exists(parmfile):
            spiderParam.readParmFile(filename=parmfile)
        # otherwise prompt user to create new one 
        else:
            spiderParam.parmNew(defaultfile=parmfile)