def __init__(self, **args): self.__super.__init__() # If we have Defaults, then update the argdict with them if hasattr(self, 'Defaults'): args = dict(self.Defaults, **args) # Check that all the required arguments have been given: we can't do # template expansion unless every argument is specified. assert self.TemplateFile, 'Must specify template file' assert self.Arguments is not None, 'Must specify some Arguments' assert set(args) == set(self.Arguments), \ 'Arguments %s missing or not recognised' % \ list(set(args).symmetric_difference(set(self.Arguments))) # Store the args self.args = args # read in the xml file xml = self.ModuleFile( os.path.join('etc', 'makeIocs', self.TemplateFile)) xml_text = open(xml).read() # substitute the args if args: xml_text = support.msi_replace_macros(args, xml_text) # make iocbuilder objects if libversion.Debug: print '< Loading objects from %s >' % self.TemplateFile self.objects = instantiateXml(xml_text) if libversion.Debug: print '</ Loading objects from %s >' % self.TemplateFile
def __init__(self, **args): self.__super.__init__() # If we have Defaults, then update the argdict with them if hasattr(self, 'Defaults'): args = dict(self.Defaults, **args) # Check that all the required arguments have been given: we can't do # template expansion unless every argument is specified. assert self.TemplateFile, 'Must specify template file' assert self.Arguments is not None, 'Must specify some Arguments' assert set(args) == set(self.Arguments), \ 'Arguments %s missing or not recognised' % \ list(set(args).symmetric_difference(set(self.Arguments))) # Store the args self.args = args # read in the xml file xml = self.ModuleFile( os.path.join('etc', 'makeIocs', self.TemplateFile)) xml_text = open(xml).read() # substitute the args obs = {} if args: msi_args = {} # mimic local variables by only passing in obs that are in args for k, v in args.items(): if getattr(self.ArgInfo.descriptions[k], 'ident', False): # for idents, make msi sub $(CAM)=CAM and add CAM to list # of objects obs[k] = v msi_args[k] = k else: # otherwise just do a straight text substitution msi_args[k] = v xml_text = support.msi_replace_macros(msi_args, xml_text) # make iocbuilder objects if libversion.Debug: print '< Loading objects from %s >' % self.TemplateFile self.objects = instantiateXml(xml_text, obs) if libversion.Debug: print '</ Loading objects from %s >' % self.TemplateFile
def CreateEdlFiles(self): # First we make a GuiBuilder object that knows how to make edm screens from dls_edm import GuiBuilder, SILENT gb = GuiBuilder(self.ioc_name, errors = SILENT) # Tell it what its paths are gb.RELEASE = os.path.join(self.iocRoot, 'configure/RELEASE') for m in sorted(libversion.ModuleBase.ListModules()): p = os.path.join(m.LibPath(), 'data') if os.path.isdir(p) and p not in gb.paths: gb.paths.append(p) for s in os.listdir(m.LibPath()): p = os.path.join(m.LibPath(), s, 'opi', 'edl') if os.path.isdir(p) and p not in gb.devpaths: gb.devpaths.append(p) # This is a list of prefixes, e.g. if our gui objects look like # CAM1.ARR, CAM1.CAM, ... # then prefixes will contain CAM1 prefixes = set() err = '''\ Meta tag should be one of the folowing: # % gui, <name>, edm, <screen_filename>[, <macros>] # % gui, <name>, edmembed, <screen_filename>[, <macros>] # % gui, <name>, edmtab, <screen_filename>[, <macros>] # % gui, <name>, shell, <command> # % gui, <name>, status[, <pv>] # % gui, <name>, sevr[, <pv>] Supplied meta tag: # % gui, ''' # For each substitution file for s in recordset.AllSubstitutions(): # For each gui meta tag for meta in getattr(s, 'guiTags', []): # substitute macros in meta tag meta = support.msi_replace_macros(s.args, meta) if libversion.Debug: print 'Processing meta tag "%s"' %meta # check it's the right length parts = meta.split(',') assert len(parts) > 1, err + meta # the first section is the name of our gui object name = parts[0].strip(' ') # the second section tells use what kind of tag it is, # e.g. edm, edmembed, status # we're only interested in edm screens switch = parts[1].strip(' ') if switch in ['edm', 'edmembed', 'edmtab']: assert len(parts) > 2, err + meta # this dictionary will be passed to GBObject.addScreen data = dict(filename = parts[2].strip(' ')) # prepare the macro list data['macros'] = ','.join(x.strip(' ') for x in parts[3:]) # special cases for tab widgets and embedded displays if switch == 'edmembed': data['embedded'] = True elif switch == 'edmtab': data['tab'] = True # If there's a dot in the name, add the first bit to # the list of prefixes if '.' in name: split = name.split('.') for i in range(1, len(split)): prefixes.add('.'.join(split[:i])) # If there isn't an object of this name, make one if not gb.get(name): gb.object(name) # Add a screen to the objects if libversion.Debug: print 'Adding edm object %s to %s screen' %(data, name) gb.get(name)[0].addScreen(**data) # Now create components out of these edm objects d = os.path.join(self.iocRoot, self.iocEdlDir) ignores = [] # sort prefixes by the number of dots in them prefixes = sorted((len(x.split(".")), x) for x in prefixes) # If we've got prefixes, make sub screens for them for _, pre in reversed(prefixes): obs = gb.get('%s.*' % pre) ignores += obs if libversion.Debug: print 'Making subscreen %s from %s' %(pre, obs) gb.object(pre, '%s Top' % pre, '', obs, d = d) # Now make a top level screen containing anything not in a sub screen obs = [x for x in gb.get('*') if x not in ignores] if libversion.Debug: print 'Making top level screen %sTop from %s' % (self.ioc_name, obs) c = gb.object('%sTop' % self.ioc_name, '%s Top' % self.ioc_name, '', obs, d = d) # Add a rule for installing edm screens self.makefile_edl.AddLine( 'DATA += $(patsubst ../%, %, $(wildcard ../*.edl))') # And a startup script for the screens gb.startupScript(filename = '%s/st%s-gui' % (d, self.ioc_name), edl = c.macrodict['FILE'], setPort = False, macros = c.macrodict['EDM_MACROS']) self.makefile_edl.AddLine('SCRIPTS += ../st%s-gui' % self.ioc_name)
def CreateEdlFiles(self): # First we make a GuiBuilder object that knows how to make edm screens from dls_edm import GuiBuilder, SILENT gb = GuiBuilder(self.ioc_name, errors=SILENT) # Tell it what its paths are gb.RELEASE = os.path.join(self.iocRoot, 'configure/RELEASE') for m in sorted(libversion.ModuleBase.ListModules()): p = os.path.join(m.LibPath(), 'data') if os.path.isdir(p) and p not in gb.paths: gb.paths.append(p) for s in os.listdir(m.LibPath()): p = os.path.join(m.LibPath(), s, 'opi', 'edl') if os.path.isdir(p) and p not in gb.devpaths: gb.devpaths.append(p) # This is a list of prefixes, e.g. if our gui objects look like # CAM1.ARR, CAM1.CAM, ... # then prefixes will contain CAM1 prefixes = set() err = '''\ Meta tag should be one of the folowing: # % gui, <name>, edm, <screen_filename>[, <macros>] # % gui, <name>, edmembed, <screen_filename>[, <macros>] # % gui, <name>, edmtab, <screen_filename>[, <macros>] # % gui, <name>, shell, <command> # % gui, <name>, status[, <pv>] # % gui, <name>, sevr[, <pv>] Supplied meta tag: # % gui, ''' # For each substitution file for s in recordset.AllSubstitutions(): # For each gui meta tag for meta in getattr(s, 'guiTags', []): # substitute macros in meta tag meta = support.msi_replace_macros(s.args, meta) if libversion.Debug: print 'Processing meta tag "%s"' % meta # check it's the right length parts = meta.split(',') assert len(parts) > 1, err + meta # the first section is the name of our gui object name = parts[0].strip(' ') # the second section tells use what kind of tag it is, # e.g. edm, edmembed, status # we're only interested in edm screens switch = parts[1].strip(' ') if switch in ['edm', 'edmembed', 'edmtab']: assert len(parts) > 2, err + meta # this dictionary will be passed to GBObject.addScreen data = dict(filename=parts[2].strip(' ')) # prepare the macro list data['macros'] = ','.join(x.strip(' ') for x in parts[3:]) # special cases for tab widgets and embedded displays if switch == 'edmembed': data['embedded'] = True elif switch == 'edmtab': data['tab'] = True # If there's a dot in the name, add the first bit to # the list of prefixes if '.' in name: split = name.split('.') for i in range(1, len(split)): prefixes.add('.'.join(split[:i])) # If there isn't an object of this name, make one if not gb.get(name): gb.object(name) # Add a screen to the objects if libversion.Debug: print 'Adding edm object %s to %s screen' % (data, name) gb.get(name)[0].addScreen(**data) # Now create components out of these edm objects d = os.path.join(self.iocRoot, self.iocEdlDir) ignores = [] # sort prefixes by the number of dots in them prefixes = sorted((len(x.split(".")), x) for x in prefixes) # If we've got prefixes, make sub screens for them for _, pre in reversed(prefixes): obs = gb.get('%s.*' % pre) ignores += obs if libversion.Debug: print 'Making subscreen %s from %s' % (pre, obs) gb.object(pre, '%s Top' % pre, '', obs, d=d) # Now make a top level screen containing anything not in a sub screen obs = [x for x in gb.get('*') if x not in ignores] if libversion.Debug: print 'Making top level screen %sTop from %s' % (self.ioc_name, obs) c = gb.object('%sTop' % self.ioc_name, '%s Top' % self.ioc_name, '', obs, d=d) # Add a rule for installing edm screens self.makefile_edl.AddLine( 'DATA += $(patsubst ../%, %, $(wildcard ../*.edl))') # And a startup script for the screens gb.startupScript(filename='%s/st%s-gui' % (d, self.ioc_name), edl=c.macrodict['FILE'], setPort=False, macros=c.macrodict['EDM_MACROS']) self.makefile_edl.AddLine('SCRIPTS += ../st%s-gui' % self.ioc_name)