Beispiel #1
0
    def __init__(self,
                 grammar=None,
                 lr_type=LR0,
                 whitespaces=False,
                 startsymbol=None):

        if grammar:
            logging.debug("Parsing Grammar")
            parser = Parser(grammar, whitespaces)
            parser.parse()

            filename = "".join([
                os.path.dirname(__file__), "/../pickle/",
                str(hash(grammar) ^ hash(whitespaces)), ".pcl"
            ])
            try:
                logging.debug("Try to unpickle former stategraph")
                f = open(filename, "r")
                start = time.time()
                self.graph = pickle.load(f)
                end = time.time()
                logging.debug("unpickling done in %s", end - start)
            except IOError:
                logging.debug("could not unpickle old graph")
                logging.debug("Creating Stategraph")
                self.graph = StateGraph(parser.start_symbol, parser.rules,
                                        lr_type)
                logging.debug("Building Stategraph")
                self.graph.build()
                logging.debug("Pickling")
                pickle.dump(self.graph, open(filename, "w"))

            if lr_type == LALR:
                self.graph.convert_lalr()

            logging.debug("Creating Syntaxtable")
            self.syntaxtable = SyntaxTable(lr_type)
            self.syntaxtable.build(self.graph)

        self.stack = []
        self.ast_stack = []
        self.all_changes = []
        self.undo = []
        self.last_shift_state = 0
        self.validating = False
        self.last_status = False
        self.error_node = None
        self.whitespaces = whitespaces
        self.status_by_version = {}
        self.errornode_by_version = {}
        self.indentation_based = False

        self.pm = PluginManager()
        self.pm.loadplugins(self)
        self.pm.do_incparse_init()

        self.previous_version = None
        logging.debug("Incremental parser done")
 def get(self):
     p = self.settings.poller
     g = StateGraph(ROOM.environment)
     g.add((SHUTTLEPRO['shuttle'], ROOM['angle'],
            Literal(p.currentShuttleAngle)))
     g.add((SHUTTLEPRO['dial'], ROOM['totalDialMovement'],
            Literal(p.totalDialMovement)))
     self.set_header('Content-type', 'application/x-trig')
     self.write(g.asTrig())
Beispiel #3
0
    def __init__(self, grammar, lr_type=LR0):
        parser = Parser(grammar)
        parser.parse()

        self.graph = StateGraph(parser.start_symbol, parser.rules, lr_type)
        self.graph.build()

        if lr_type == LALR:
            self.graph.convert_lalr()

        self.syntaxtable = SyntaxTable(lr_type)
        self.syntaxtable.build(self.graph)

        self.stack = []
        self.ast_stack = []
Beispiel #4
0
    def from_dict(self, rules, startsymbol, lr_type, whitespaces, pickle_id, precedences):
        self.graph = None
        self.syntaxtable = None
        if pickle_id:
            filename = "".join([os.path.dirname(__file__), "/../pickle/", str(pickle_id ^ hash(whitespaces)), ".pcl"])
            try:
                f = open(filename, "r")
                self.syntaxtable = pickle.load(f)
            except IOError:
                pass
        if self.syntaxtable is None:
            self.graph = StateGraph(startsymbol, rules, lr_type)
            self.graph.build()
            self.syntaxtable = SyntaxTable(lr_type)
            self.syntaxtable.build(self.graph, precedences)
            if pickle_id:
                pickle.dump(self.syntaxtable, open(filename, "w"))

        self.whitespaces = whitespaces
Beispiel #5
0
    def get(self):
        log.debug("start graph")
        g = StateGraph(URIRef("http://bigasterisk.com/map"))

        for user in [URIRef("http://bigasterisk.com/foaf.rdf#drewp"),
                     URIRef("http://bigasterisk.com/kelsi/foaf.rdf#kelsi"),
                     ]:
            log.debug("find points for %s", user)
            pt = list(mongo.find({'user':user}, sort=[TIME_SORT], limit=1))
            if not pt:
                continue
            pt = pt[0]
            t = datetime.datetime.fromtimestamp(
                pt_sec(pt), tzutc()).astimezone(tzlocal())
            g.add((user, MAP['lastSeen'], Literal(t)))

            ago = int(time.time() - pt_sec(pt))
            g.add((user, MAP['lastSeenAgoSec'], Literal(ago)))
            g.add((user, MAP['lastSeenAgo'], Literal(
                "%s seconds" % ago if ago < 60 else
                ("%.1f minutes" % (ago / 60) if ago < 3600 else
                 ("%.1f hours" % (ago / 3600))))))

            log.debug("describeLocationFull")
            desc, targetUri, targetName, dist = describeLocationFull(
                config,
                pt['longitude'], pt['latitude'],
                pt.get('horizAccuracy', pt.get('accuracy', 0)),
                str(user))

            g.add((user, MAP['lastNear'], targetUri))
            g.add((targetUri, RDFS.label, Literal(targetName)))
            g.add((user, MAP['lastDesc'], Literal(desc)))
            g.add((user, MAP['distanceToHomeM'], Literal(metersFromHome(
                config, user, pt['longitude'], pt['latitude']))))
            if ago < 60*15:
                g.add((user, MAP['recentlyNear'], targetUri))
            log.debug("added %s", user)

        self.set_header("content-type", 'application/x-trig')
        ret = g.asTrig()
        log.debug("return graph")
        self.write(ret)
Beispiel #6
0
class ProcessStatus(cyclone.web.RequestHandler):
    def get(self, addr):
        """run state of all processes on this supervisor"""
        serv = getConnection(self.settings.xmlrpcConnections,
                             self.settings.addresses[addr])
        for tries in range(3):
            try:
                infos = serv.supervisor.getAllProcessInfo()
            except Exception, e:
                pass
            else:
                break
        else:
            raise e

        graph = StateGraph(ctx=CL['supervisors'])
        for p in infos:
            # this uri design is not very good yet. should just be
            # host->supinstance->processid
            processUri = URIRef("http://bigasterisk.com/magma/sup/%s/%s" %
                                (addr, p['name']))
            graph.add((processUri, RDF.type,
                       URIRef("http://bigasterisk.com/ns/command/v1#Process")))
            if p['name'].startswith("cmd_"):
                graph.add(
                    (processUri, RDF.type,
                     URIRef(
                         "http://bigasterisk.com/ns/command/v1#CommandProcess")
                     ))

            graph.add((processUri, RDFS.label, Literal(p['name'])))