Example #1
0
    def setUpClass(cls):
        logging.basicConfig(level=logging.ERROR)
        #if os.path.exists('models'):
            #shutil.rmtree('models')
        #shutil.copytree('testmodels', 'models')
        #cls.stopq = Queue()

        #cls.serverp = Process(target=server.runServer, args=('models', 'server-test.conf', 'admins-test.yaml', 'oauth-clients-test.json', 'oauth_access_tokens.dat', logging.DEBUG, cls.stopq, 'client_secrets_google.json'))
        #cls.serverp.start()
        #cls.stopq.put('test')

        #time.sleep(1)

        client_secrets = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'client_secrets.json')
        p = None # httplib2.ProxyInfo(proxy_type=httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, proxy_host='www-cache.it.usyd.edu.au', proxy_port=8000)
        cls.um = client.util.LoginFromClientSecrets(filename=client_secrets, 
            http=httplib2.Http(proxy_info=p, disable_ssl_certificate_validation=True), 
            credentials='server_test_cred.dat')
        cobj = client.Context(Identifier='test', Description='a test component')
        t = cls.um.mkcontext(context=[''], contextobj=cobj)
        cobj = client.Component(Identifier="firstname", component_type="attribute", Description="First name", value_type="string")
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)
        cobj = client.Component(Identifier="lastname", component_type="attribute", Description="Last name", value_type="string")
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)
        cobj = client.Component(Identifier="gender", component_type="attribute", Description="Gender", value_type="enum", value_list=['male','female'])
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)
        cobj = client.Component(Identifier="email", component_type="attribute", Description="email address", value_type="string")
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)
        cobj = client.Component(Identifier="otheremail", component_type="attribute", Description="email address", value_type="string")
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)

        vobj = client.View(Identifier="fullname", component_list=["firstname", "lastname"])
        cls.um.mkview(context=["test"], viewobj=vobj)
Example #2
0
    def setUpClass(cls):
        logging.basicConfig(level=logging.ERROR)

        client_secrets = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'client_secrets.json')
        cls.server_uri = json.loads(
            open(client_secrets,
                 'r').read())['installed']['token_uri'][:-len('request_token')]

        #p = httplib2.ProxyInfo(proxy_type=httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, proxy_host='www-cache.it.usyd.edu.au', proxy_port=8000)
        p = None
        cls.um = client.util.LoginFromClientSecrets(
            filename=client_secrets,
            http=httplib2.Http(proxy_info=p,
                               disable_ssl_certificate_validation=True),
            credentials='server_test_cred.dat')
        cobj = client.Context(Identifier='test',
                              Description='a test component')
        t = cls.um.mkcontext(context=[''], contextobj=cobj)
        cobj = client.Component(Identifier="firstname",
                                component_type="attribute",
                                Description="First name",
                                value_type="string")
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)
        cobj = client.Component(Identifier="lastname",
                                component_type="attribute",
                                Description="Last name",
                                value_type="string")
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)
        cobj = client.Component(Identifier="gender",
                                component_type="attribute",
                                Description="Gender",
                                value_type="enum",
                                value_list=['male', 'female'])
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)
        cobj = client.Component(Identifier="email",
                                component_type="attribute",
                                Description="email address",
                                value_type="string")
        res = cls.um.mkcomponent(context=["test"], componentobj=cobj)

        vobj = client.View(Identifier="fullname",
                           component_list=["firstname", "lastname"])
        cls.um.mkview(context=["test"], viewobj=vobj)
Example #3
0
def install_inactivity(um):
    try:
        reslist = um.ask(context=["Devices", "activity_monitor"])
        return
    except:
        pass

    ctx_obj = client.Context(Identifier="activity_monitor",
                             Description="Watch computer usage",
                             perms={
                                 'ask': True,
                                 'tell': True,
                                 "resolvers":
                                 ["all", "last10", "last1", "goal"]
                             },
                             resolver=None,
                             objectType="Context")
    context = ['Devices']
    um.mkcontext(context, ctx_obj)
    context.append('activity_monitor')

    ctx_obj = client.Context(Identifier="activity",
                             Description="Extract data from activity watcher",
                             perms={
                                 'ask': True,
                                 'tell': True,
                                 "resolvers":
                                 ["all", "last10", "last1", "goal"]
                             },
                             resolver=None,
                             objectType="Context")
    um.mkcontext(context, ctx_obj)
    context.append('activity')

    cobj = client.Component(
        Identifier="data",
        component_type="attribute",
        value_type="number",
        resolver=None,
        Description=
        "0 on inactivity detection, 1 on activity detection, -1 on shutdown")
    um.mkcomponent(context=context, componentobj=cobj)
Example #4
0
    def test_make_del_age(self):
        cobj = client.Component(Identifier="age",
                                component_type="attribute",
                                Description="age",
                                goals=[['Personal', 'Health', 'weight']],
                                value_type="number")
        res = self.um.mkcomponent(context=["test"], componentobj=cobj)

        ev = client.Evidence(evidence_type="explicit", value=17)
        self.um.tell(context=["test"], componentid='age', evidence=ev)
        reslist = self.um.ask(context=["test"],
                              view=['age'],
                              resolver={'evidence_filter': "all"})

        self.assertEqual(reslist[0].value, 17)
        self.um.delcomponent(context=["test"], componentid="age")

        info = self.um.ask(context=["test"], showcontexts=True)
        (cobjlist, contexts, theviews, thesubs) = info
        self.assertNotIn(u'age', cobjlist)
Example #5
0
    def install_contexts(self, um):
        try:
            reslist = um.ask(context=['Apps','Logging'])
            return
        except:
            pass

        context = ['Apps']
        ctx_obj = client.Context(Identifier="Logging",
                  Description="The logging app",
                  perms={'ask':True, 'tell':True,
                  "resolvers": ["all","last10","last1","goal"]},
                  resolver=None, objectType="Context")
        print "Creating logging context "
        um.mkcontext(context,ctx_obj)
        context.append('Logging')

        cobj = client.Component(Identifier="logged_items", component_type="activity", value_type="enum", 
                                       value_list=[i for i in item_list.keys()], resolver=None ,Description="All the items logged")
        um.mkcomponent(context=context, componentobj=cobj)
Example #6
0
    def do_mkcomponent(self, line):
        """mkcomponent component_name
                make a new component"""

        line = line.split()
        if len(line) != 1:
            print "usage: mkcomponent compname"
            return
        contxt = self.context
        comp = line[0]
        compdesc = raw_input("Component description? ")
        print "Component type:"
        for ct in client.Component.ComponentTypes:
            print client.Component.ComponentTypes.index(ct), ct
        ctindex = int(raw_input("Index? "))
        if (ctindex < 0) or (ctindex >
                             len(client.Component.ComponentTypes) - 1):
            print "Index out of range"
            return
        comptype = client.Component.ComponentTypes[ctindex]

        print "Value type:"
        for ct in client.Component.ValueTypes:
            print client.Component.ValueTypes.index(ct), ct
        ctindex = int(raw_input("Index? "))
        if (ctindex < 0) or (ctindex > len(client.Component.ValueTypes) - 1):
            print "Index out of range"
            return
        valtype = client.Component.ValueTypes[ctindex]

        print "Creating new component '%s', type '%s', description '%s', value type '%s'" % (
            comp, comptype, compdesc, valtype)
        ok = raw_input("Ok?[N] ")
        if ok != 'Y':
            return
        cobj = client.Component(Identifier=comp,
                                component_type=comptype,
                                Description=compdesc,
                                value_type=valtype)
        res = self.um.mkcomponent(context=contxt, componentobj=cobj)