예제 #1
0
    def proc(self,
        Merchant,
        Category,
        ProcedureType,
        Price,
        Booked,
        Time,
        Date,
        SpecificProcedure,
        ):
        res, node = [], Node()

        res.append(
            Statement(node, PROVIDER, Merchants.get_merchant(Merchant))
            )

        # Normalize date.
        Date = datetime.strptime(Date, DATE_FORMAT).date().strftime(DATE_FORMAT)

        res.extend((
            Statement(node, DATE, Date),
            Statement(node, FROM_TIME, Time),
            Statement(node, PRICE, Price.strip()),
            ))

        res.append(
            Statement(node, TREATMENT, get_treatment(Category, ProcedureType, SpecificProcedure))
            )

        return res
예제 #2
0
def add_staff_member(spa, staffmember):
    T = get_spa_from_label(spa)
    spa = T[0] if T else add_provider(spa, spa)
    s = Node()
    for s in (
            Statement(s, LABEL, staffmember),
            Statement(spa, EMPLOYS, s),
    ):
        M.add_statement(s)
    return s
예제 #3
0
 def addAction(self, label, prop_src, service):
     subject = DOME_DATA['action/' + str(uuid.uuid4())]
     statements = [
         Statement(subject, rdf.type, DOME.Action),
         Statement(subject, rdfs.label, label),
         Statement(subject, DOME.actuates, prop_src),
         Statement(subject, DOME.callservice, command)
     ]
     self._add(statements)
     return subject
예제 #4
0
def get_category(cat):
    if cat in Categories:
        return Categories[cat]

    c = Categories[cat] = Node()
    additional_statements.extend((
        Statement(c, NAME, cat),
        Statement(c, TYPE, CATEGORY),
        ))

    return c
예제 #5
0
 def addCondition(self, label, prop_src, value, operator):
     subject = DOME_DATA['condition/' + label + str(uuid.uiid4())]
     statements = [
         Statement(subject, rdf.type, DOME.Condition),
         Statement(subject, rdfs.label, label),
         Statement(subject, DOME.observes, prop_src),
         Statement(subject, DOME.target, value),
         Statement(subject, DOME.operatortype, operator)
     ]
     self._add(statements)
     return subject
예제 #6
0
 def addProperty(self, label, value, updated, changed):
     subject = DOME_DATA['property/' + label + str(uuid.uuid4())]
     statements = [
         Statement(subject, rdf.type, DOME.Property),
         Statement(subject, rdfs.label, label),
         Statement(subject, DOME.value, value),
         Statement(subject, DOME.last_updated, updated),
         Statement(subject, DOME.last_changed, changed)
     ]
     self._add(statements)
     return subject
예제 #7
0
def create_availability_with_trenche(trenche, day):
    T = get_trenche_from_label(trenche)
    if not T:
        if __debug__:
            print 'unknown trenche:', repr(trenche)
        return False  # raise exception?
    trenche = T[0]
    avail = Node()
    M.add_statement(Statement(avail, TYPE, AVAIL))
    M.add_statement(Statement(avail, SUPPORTS, trenche))
    M.add_statement(Statement(avail, DATE, day))
    return avail
예제 #8
0
def get_subtype(st, cat):
    if st in ProcedureTypes:
        return ProcedureTypes[st]

    s = ProcedureTypes[st] = Node()
    additional_statements.extend((
        Statement(s, NAME, st),
        Statement(s, TYPE, PROCTYPE),
        Statement(s, SUBCAT, cat),
        ))

    return s
예제 #9
0
def get_treatment(cat, subtype, treat):
    if treat in Treatments:
        return Treatments[treat]
    cat = get_category(cat)
    sbt = get_subtype(subtype, cat)
    t = Treatments[treat] = Node()
    additional_statements.extend((
        Statement(t, NAME, treat),
        Statement(t, TYPE, TREATMENT),
        Statement(t, SUBCAT, sbt),
        ))
    return t
예제 #10
0
 def addAutomation(self, label, trigger, actions, enabled=True):
     subject = DOME_DATA['automation/' + label + str(uuid.uuid4())]
     statements = [
         Statement(subject, rdf.type, DOME.Automation),
         Statement(subject, rdfs.label, label),
         Statement(subject, DOME.triggeredby, DOME.Trigger),
         Statement(subject, DOME.isenabled, enabled)
     ]
     for action in actions:
         statements.append(subject, DOME.performs, actions)
     self._add(statements)
     return subject
예제 #11
0
 def addTrigger(self, label, triggers, conditions, operator):
     subject = DOME_DATA['trigger/' + label + str(uuid.uuid4())]
     statements = [
         Statement(subject, rdf.type, DOME.Trigger),
         Statement(subject, rdfs.label, label),
         Statement(subject, DOME.operatortype, operator)
     ]
     for trigger in triggers:
         statements.append(subject, DOME.hassubtrigger, trigger)
     for condition in conditions:
         statements.append(subject, DOME.hascondition, condition)
     self._add(statements)
     return subject
예제 #12
0
def GET_staff_member(spa, staff_tag):
    q = get_staff_member(spa, staff_tag)
    s = Statement(subject=q['staffmember'])
    stream = M.find_statements(s)
    xml = serialize_stream(stream)
    ##    xml = S.serialize_model_to_string(M)
    return xml
예제 #13
0
def add_thing(name, label, kind):
    thing = Node()
    f = lambda p, o: Statement(thing, p, o)
    for s in (
            f(TYPE, kind),
            f(NAME, name),
            f(LABEL, label),
    ):
        M.add_statement(s)
    return thing
예제 #14
0
def add_treatment_to_trenche(treatment, trenche):
    T = get_treatment_from_label(treatment)
    treatment = T[0] if T else add_treatment(treatment)

    T = get_trenche_from_label(trenche)
    trenche = T[0] if T else add_trenche(trenche)

    s = Statement(trenche, SUPPORTS, treatment)
    if __debug__:
        print s
    M.add_statement(s)
예제 #15
0
def create_availability(location, trenche, day, from_time, to_time):
    '''
    Return a status message or something to indicate whether the
    availability slot was created or not.
    '''

    print "Check location.", location
    # location = get_location_from_label(location)

    print "Check day and time", day, from_time, to_time  # (for, I dunno, conflicts or something.)
    day = day.strftime(DATE_FORMAT)

    avail = create_availability_with_trenche(trenche, day)
    if not avail:
        return 'FAIL %r %r %r %r %r' % (location, trenche, day, from_time,
                                        to_time)

    M.add_statement(Statement(avail, WHERE, location))
    M.add_statement(Statement(avail, FROM_TIME, from_time.isoformat()))
    M.add_statement(Statement(avail, TO_TIME, to_time.isoformat()))
예제 #16
0
    def addDevice(self, label, actuates, prop_src, ha_name, ha_type):
        subject = DOME_DATA[cleanUri(ha_name)]
        statements = [
            Statement(subject, rdf.type, DOME.Device),
            Statement(subject, rdfs.label, label),
            Statement(subject, DOME.ha_name, ha_name),
            Statement(subject, DOME.ha_type, ha_type)
        ]
        assert (isinstance(prop_src, Node))
        if (actuates):
            statements.append(Statement(subject, DOME.actuates, prop_src))
        else:
            statements.append(Statement(subject, DOME.observes, prop_src))

        self._add(statements)
        return subject
예제 #17
0
 def addWebProperty(self,
                    label,
                    host,
                    ext_res_src,
                    ext_prop_src,
                    poll,
                    graph=None):
     subject = DOME_DATA['webproperty/' + str(uuid.uuid4())]
     statements = [
         Statement(subject, rdf.type, DOME.WebProperty),
         Statement(subject, rdfs.label, label),
         Statement(subject, DOME.hostedby, host),
         Statement(subject, DOME.resource, ext_res_src),
         Statement(subject, DOME.property, ext_prop_src),
         Statement(subject, DOME.poll, str(poll))
     ]
     if (graph):
         statements.append(Statement(subject, DOME.graphname, graph))
     self._add(statements)
     return subject
예제 #18
0
def friend2config(friend_model, friend, seeAlso, subconfig, data):

    try:
        from RDF import Model, NS, Parser, Statement
    except:
        return

    dc = NS('http://purl.org/dc/elements/1.1/')
    foaf = NS('http://xmlns.com/foaf/0.1/')
    rdf = NS('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
    rdfs = NS('http://www.w3.org/2000/01/rdf-schema#')

    # FOAF InverseFunctionalProperties
    ifps = [
        foaf.mbox, foaf.mbox_sha1sum, foaf.jabberID, foaf.aimChatID,
        foaf.icqChatID, foaf.yahooChatID, foaf.msnChatID, foaf.homepage,
        foaf.weblog
    ]

    model = load_model(data, seeAlso)

    for statement in model.find_statements(
            Statement(None, rdf.type, foaf.Person)):

        samefriend = statement.subject

        # maybe they have the same uri
        if friend.is_resource() and samefriend.is_resource(
        ) and friend == samefriend:
            foaf2config(model, subconfig, samefriend)
            return

        for ifp in ifps:
            object = model.get_target(samefriend, ifp)
            if object and object == friend_model.get_target(friend, ifp):
                foaf2config(model, subconfig, samefriend)
                return
예제 #19
0
 def load(self, uri='', name=''):
     if uri:
         return self._g.load(uri=uri, name=name, handler=self._h)
     st = os.stat(self._p0)
     if not stat.S_ISDIR(st.st_mode):
         self._editable = True
         p = Parser(self._f0)
         assert p.parse_into_model(self._g,
                                   'file:' + self._p0,
                                   base_uri=self._base,
                                   handler=self._h)
     else:
         self._g.append(
             Statement(Node(uri_string=self._base), ns.rdf['type'],
                       ns.stat['Directory']))
         for k in os.listdir(self._p0):
             st = os.stat(self._p0 + '/' + k)
             if stat.S_ISDIR(st.st_mode):
                 kn = Node(uri_string=str(k) + '/')
                 self._g.append(
                     Statement(kn, ns.rdf['type'], ns.stat['Directory']))
             else:
                 kn = Node(uri_string=str(k))
             self._g.append(
                 Statement(Node(uri_string=self._base), ns.rdfs['member'],
                           kn))
             self._g.append(
                 Statement(kn, ns.stat['atime'],
                           Node(literal=str(int(st.st_atime)))))
             self._g.append(
                 Statement(kn, ns.stat['ctime'],
                           Node(literal=str(int(st.st_ctime)))))
             self._g.append(
                 Statement(kn, ns.stat['mtime'],
                           Node(literal=str(int(st.st_mtime)))))
             self._g.append(
                 Statement(kn, ns.stat['size'],
                           Node(literal=str(int(st.st_size)))))
예제 #20
0
 def updateStatement(self, src, pred, obj):
     for stmt in self.model.find_statements(Statement(src, pred, None)):
         del self.model[stmt]
     self.model.append(Statement(src, pred, obj))
예제 #21
0
import sys, os
sys.path.append(os.path.abspath(os.path.join('lib', 'redland', 'bindings', 'python')))
from RDF import Uri, Statement

from dome.db.graph import Graph
from dome.config import DOME

if (len(sys.argv) != 2):
    sys.exit()

resource = sys.argv[1]
for stmt in Graph.getModel().find_statements(Statement(Uri(resource), None, None)):
    del Graph.getModel()[stmt]

for stmt in Graph.getModel().find_statements(Statement(None, None, Uri(resource))):
    del Graph.getModel()[stmt]
예제 #22
0
def foaf2config(rdf, config, subject=None, section=None):

    if not config or not config.sections():
        return

    # there should be only be 1 section
    if not section: section = config.sections().pop()

    try:
        from RDF import Model, NS, Parser, Statement
    except:
        return

    # account mappings, none by default
    # form: accounts = {url to service homepage (as found in FOAF)}|{URI template}\n*
    # example: http://del.icio.us/|http://del.icio.us/rss/{foaf:accountName}
    accounts = load_accounts(config, section)

    depth = 0

    if (config.has_option(section, 'depth')):
        depth = config.getint(section, 'depth')

    model = load_model(rdf, section)

    dc = NS('http://purl.org/dc/elements/1.1/')
    foaf = NS('http://xmlns.com/foaf/0.1/')
    rdfs = NS('http://www.w3.org/2000/01/rdf-schema#')
    rdf = NS('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
    rss = NS('http://purl.org/rss/1.0/')

    for statement in model.find_statements(
            Statement(subject, foaf.weblog, None)):

        # feed owner
        person = statement.subject

        # title is required (at the moment)
        title = model.get_target(person, foaf.name)
        if not title: title = model.get_target(statement.object, dc.title)
        if not title:
            continue

        # blog is optional
        feed = model.get_target(statement.object, rdfs.seeAlso)
        if feed and rss.channel == model.get_target(feed, rdf.type):
            feed = str(feed.uri)
            if not config.has_section(feed):
                config.add_section(feed)
                config.set(feed, 'name', str(title))

        # now look for OnlineAccounts for the same person
        if accounts.keys():
            for statement in model.find_statements(
                    Statement(person, foaf.holdsAccount, None)):
                rdfaccthome = model.get_target(statement.object,
                                               foaf.accountServiceHomepage)
                rdfacctname = model.get_target(statement.object,
                                               foaf.accountName)

                if not rdfaccthome or not rdfacctname: continue

                if not rdfaccthome.is_resource() or not accounts.has_key(
                        str(rdfaccthome.uri)):
                    continue

                if not rdfacctname.is_literal(): continue

                rdfacctname = rdfacctname.literal_value['string']
                rdfaccthome = str(rdfaccthome.uri)

                # shorten feed title a bit
                try:
                    servicetitle = rdfaccthome.replace('http://',
                                                       '').split('/')[0]
                except:
                    servicetitle = rdfaccthome

                feed = accounts[rdfaccthome].replace("{foaf:accountName}",
                                                     rdfacctname)
                if not config.has_section(feed):
                    config.add_section(feed)
                    config.set(feed, 'name', "%s (%s)" % (title, servicetitle))

        if depth > 0:

            # now the fun part, let's go after more friends
            for statement in model.find_statements(
                    Statement(person, foaf.knows, None)):
                friend = statement.object

                # let's be safe
                if friend.is_literal(): continue

                seeAlso = model.get_target(friend, rdfs.seeAlso)

                # nothing to see
                if not seeAlso or not seeAlso.is_resource(): continue

                seeAlso = str(seeAlso.uri)

                if not config.has_section(seeAlso):
                    config.add_section(seeAlso)
                    copy_options(config, section, seeAlso, {
                        'content_type': 'foaf',
                        'depth': str(depth - 1)
                    })
                try:
                    from planet.config import downloadReadingList
                    downloadReadingList(
                        seeAlso, config, lambda data, subconfig: friend2config(
                            model, friend, seeAlso, subconfig, data), False)
                except:
                    pass

    return
예제 #23
0
 def testCreateAvailabilityWithTrenche(self):
     add_treatment_to_trenche('Banana Slug Dip', 'A')
     result = create_availability_with_trenche("A", "11/03/2011")
     self.assert_(Statement(result, TYPE, AVAIL) in spasui.models.M)
     self.assert_(Statement(result, DATE, "11/03/2011") in spasui.models.M)