Esempio n. 1
0
def specialiser(targetdir,input_fileobj,output_fileobj):

    # Read APPLICATION and ABSTRACTSOURCE tags
    abstract_lsts_name, application_name = None, None

#    for line in file(infofilename):
    for line in input_fileobj:
        if line[:15]=="ABSTRACTSOURCE:":
            abstract_lsts_name=os.path.join(targetdir,line.split(":")[1].strip()+".lsts")

        elif line[:12]=="APPLICATION:":
            application_name=line.split(":")[1].strip()

    if abstract_lsts_name==None: 
        raise SpecialiserError("ABSTRACTSOURCE not found")

    # Open abstract LSTS file
    abslsts=lsts.reader( open(abstract_lsts_name,'r') )
    # the new lsts is based on the abslsts
    newlsts=lsts.writer( lsts_object=abslsts ) 

    # Specialise the abstract LSTS by replacing @APPLICATION with concrete
    # application name in the action names of the LSTS
    newactionnames=[]
    for index,action in enumerate(abslsts.get_actionnames()):
        if application_name!=None and "@APPLICATION" in action:
            newactionnames.append(action.replace('@APPLICATION', application_name))
        else:
            newactionnames.append(action)

    # Write out the specialised LSTS.
    newlsts.set_actionnames(newactionnames)
    newlsts.write( output_fileobj )
Esempio n. 2
0
def gt(input_fileobj,output_fileobj,keep_labels,rules):
    outfile = output_fileobj
    if input_fileobj == None:
        inlsts = None
    else:
        try:
            inlsts=lsts.reader(input_fileobj)
        except Exception,e:
            raise GTError("Could not read input lsts from '%s'%s%s" % \
                              (str(input_fileobj),os.linesep,e))
Esempio n. 3
0
def gt(input_fileobj, output_fileobj, keep_labels, rules):
    outfile = output_fileobj
    if input_fileobj == None:
        inlsts = None
    else:
        try:
            inlsts = lsts.reader(input_fileobj)
        except Exception, e:
            raise GTError("Could not read input lsts from '%s'%s%s" % \
                              (str(input_fileobj),os.linesep,e))
Esempio n. 4
0
def rextendedrules(working_dir, parse_warnings,input_fileobj,output_fileobj):

    parser=Rextfile_parser()
    filenames={}
    alphabets={}
    lstsnumber={}
    rules=[]
    alreadyprintedrules={}

    # rules = [
    #  [ [ (quant,lstskey, actionname), ..., (quant,key_n, name_n) ],
    #    result,
    #    next_expanded_re_number,
    #    ruletype ::= RULEROW | COMMENTROW,
    #    row_number_in_input_file,
    #    dict: participant -> number of appearances in the row,
    #  ],
    #  similar rule row 2
    #  ...
    #  ]

    # Parse rextended rules
    for rowindex,l in enumerate(input_fileobj):
        row=parser.processrow(l)
        if row:
            for processname in parser.expand_procarray(row[0]):
                filenames[processname]=row[1]
                lstsnumber[processname]=len(filenames)
            continue
        row=parser.rulerow(l)
        if row:
            rules.append([row[0],row[1],1,RULEROW,rowindex+1,{}])
            continue
        row=parser.commentrow(l)
        if row:
            rules.append([row,0,0,COMMENTROW,rowindex+1])
            continue
        if parse_warnings:
            sys.stderr.write("WARNING: rextendedrules: could not parse row %s:%s\t'%s'%s" % (rowindex+1,os.linesep,l.strip(),os.linesep))

    # Get actionnames sections of mentioned lsts files
    for key in filenames:
        r=lsts.reader()
        try:
            r.read(open(os.path.join(working_dir,filenames[key]),'r'))
            alphabets[key]=r.get_actionnames()
        except Exception, e:
            raise RextendedrulesError("(in file '%s'): %s%s" % (filenames[key],e,os.linesep))
Esempio n. 5
0
def rextendedrules(working_dir, parse_warnings,input_fileobj,output_fileobj):

    parser=Rextfile_parser()
    filenames={}
    alphabets={}
    lstsnumber={}
    rules=[]

    # rules = [
    #  [ [ (quant,lstskey, actionname), ..., (quant,key_n, name_n) ],
    #    result,
    #    next_expanded_re_number,
    #    ruletype ::= RULEROW | COMMENTROW,
    #    row_number_in_input_file,
    #    dict: participant -> number of appearances in the row,
    #  ],
    #  similar rule row 2
    #  ...
    #  ]

    # Parse rextended rules
    for rowindex,l in enumerate(input_fileobj):
        row=parser.processrow(l)
        if row:
            for processname in parser.expand_procarray(row[0]):
                filenames[processname]=row[1]
                lstsnumber[processname]=len(filenames)
            continue
        row=parser.rulerow(l)
        if row:
            rules.append([row[0],row[1],1,RULEROW,rowindex+1,{}])
            continue
        row=parser.commentrow(l)
        if row:
            rules.append([row,0,0,COMMENTROW,rowindex+1])
            continue
        if parse_warnings:
            sys.stderr.write("WARNING: rextendedrules: could not parse row %s:%s\t'%s'%s" % (rowindex+1,os.linesep,l.strip(),os.linesep))

    # Get actionnames sections of mentioned lsts files
    for key in filenames:
        r=lsts.reader()
        try:
            r.read(open(os.path.join(working_dir,filenames[key]),'r'))
            alphabets[key]=r.get_actionnames()
        except Exception, e:
            raise RextendedrulesError("(in file '%s'): %s%s" % (filenames[key],e,os.linesep))
Esempio n. 6
0
 def loadFromObject(self,rules_file_contents=None):
     parser=rules_parser.ExtRulesParser()
     
     # Load LSTSs mentioned in the rules to the lstslist
     lstss=parser.parseLstsFiles(rules_file_contents)
     for lstsnum,lstsfile in lstss:
         lstsobj=lsts.reader()
         if self._dirprefix:
             filename=self._dirprefix+"/"+lstsfile
         else:
             filename=lstsfile
         try:
             lstsobj.read(file(filename))
             self.log("Model component %s loaded from '%s'" % (len(self._lstslist),filename))
         except Exception,(errno,errstr):
             raise ValueError("Could not read lsts '%s':\n(%s) %s" % (filename,errno,errstr))
         self._lstslist.append((lstsnum,lstsobj))
Esempio n. 7
0
def specialiser(targetdir, input_fileobj, output_fileobj):

    # Read APPLICATION and ABSTRACTSOURCE tags
    abstract_lsts_name, application_name = None, None

    #    for line in file(infofilename):
    for line in input_fileobj:
        if line[:15] == "ABSTRACTSOURCE:":
            abstract_lsts_name = os.path.join(
                targetdir,
                line.split(":")[1].strip() + ".lsts")

        elif line[:12] == "APPLICATION:":
            application_name = line.split(":")[1].strip()

    if abstract_lsts_name == None:
        raise SpecialiserError("ABSTRACTSOURCE not found")

    # Open abstract LSTS file
    abslsts = lsts.reader(open(abstract_lsts_name, 'r'))
    # the new lsts is based on the abslsts
    newlsts = lsts.writer(lsts_object=abslsts)

    # Specialise the abstract LSTS by replacing @APPLICATION with concrete
    # application name in the action names of the LSTS
    newactionnames = []
    for index, action in enumerate(abslsts.get_actionnames()):
        if application_name != None and "@APPLICATION" in action:
            newactionnames.append(
                action.replace('@APPLICATION', application_name))
        else:
            newactionnames.append(action)

    # Write out the specialised LSTS.
    newlsts.set_actionnames(newactionnames)
    newlsts.write(output_fileobj)
Esempio n. 8
0
 def loadFromFile(self, file_like_object):
     lsts_reader = lsts.reader()
     lsts_reader.read(file_like_object)
     self.loadFromObject(lsts_reader)
Esempio n. 9
0
 def loadFromFile(self,file_like_object):
     lsts_reader=lsts.reader()
     lsts_reader.read(file_like_object)
     self.loadFromObject(lsts_reader)