Ejemplo n.º 1
0
 def delete(self, request, operation):
     operation = "/%s" % operation
     baseUrl = cleanUrl(settings.CATALOGUE_URL)
     conn = Connection(baseUrl)
     result = conn.request_delete(operation) #, headers={'Accept':'application/json'})
     response = HttpResponse(result['body'], mimetype='application/json; charset=UTF-8')
     return response
Ejemplo n.º 2
0
 def __storeGadget(self, gadgetMetaData):
     gadgetPath = path.join(STORAGE_DIR,
                            gadgetMetaData['gadgetRelativePath'])
     gadgetZipFileName = path.join(gadgetPath, STORAGE_GADGET_ZIP_NAME)
     #Remote Storage
     if gadgetMetaData.has_key('gadgetDataUri'):
         conn = Connection(gadgetMetaData['gadgetDataUri'])
         if settings.STORAGE_FORMAT == 'base64string':
             f = open(gadgetZipFileName, 'rb')
             data = f.read()
             f.close()
             data = binascii.b2a_base64(data)
             format = settings.STORAGE_FORMAT
         else:
             data = '/'.join(
                 [gadgetMetaData['gadgetUri'], STORAGE_GADGET_ZIP_NAME])
             format = 'URL'
         body = {'Data': data, 'DataType': format}
         result = conn.request_post(resource='',
                                    body=str(json_encode(body)),
                                    headers={
                                        'Accept': 'application/json',
                                        'Content-Type': 'application/json'
                                    })
         if not isValidResponse(result):
             raise Exception(result['body'])
     #Local Storage
     else:
         un = unzip.unzip()
         un.extract(gadgetZipFileName, gadgetPath)
         remove(gadgetZipFileName)
Ejemplo n.º 3
0
 def delete(self, request, operation):
     operation = "/%s" % operation
     baseUrl = cleanUrl(settings.CATALOGUE_URL)
     conn = Connection(baseUrl)
     result = conn.request_delete(
         operation)  #, headers={'Accept':'application/json'})
     response = HttpResponse(result['body'],
                             mimetype='application/json; charset=UTF-8')
     return response
 def _make_request(self, base_url, resource, args=None):
     """
     wrapper for rest client and json libraries
     """
     
     conn = Connection(base_url)
     # TODO: is "headers" part necessary?
     response = conn.request_get(resource, args, headers={'Accept':'text/json'})
     data = json.loads(response['body'])
     return data
Ejemplo n.º 5
0
    def delete(self, *args, **kwargs):
        try:
            json = simplejson.loads(self.data)

            if json['gadgetResource'] != None:
                conn = Connection(json['gadgetResource'])
                result = conn.request_delete(resource='', headers={'Accept':'application/json'})
                if not isValidResponse(result):
                    raise Exception(result['body'])
        except Exception, e:
            pass
Ejemplo n.º 6
0
 def delete(self, *args, **kwargs):
     for storage in self.storage_set.all():
         storage.delete()
     # Delete screen instances
     json = simplejson.loads(self.data)
     for screen in json['definition']['screens']:
         conn = Connection(screen['uri'])
         result = conn.request_delete('', headers={'Accept': 'text/json'})
         if not isValidResponse(result):
             raise Exception(result['body'])
     super(Screenflow, self).delete(*args, **kwargs)
Ejemplo n.º 7
0
 def delete(self, *args, **kwargs):
     for storage in self.storage_set.all():
         storage.delete()
     # Delete screen instances
     json = simplejson.loads(self.data)
     for screen in json['definition']['screens']:
         conn = Connection(screen['uri'])
         result = conn.request_delete('', headers={'Accept':'text/json'})
         if not isValidResponse(result):
             raise Exception(result['body'])
     super(Screenflow, self).delete(*args, **kwargs)
Ejemplo n.º 8
0
 def unshare(self):
     if (self.uri != None) and (self.uri != ''):
         conn = Connection(self.uri)
         result = conn.request_delete('', headers={'Accept':'text/json'})
         if not isValidResponse(result):
             raise Exception(result['body'])
         else:
             data = simplejson.loads(self.data)
             del data['uri']
             self.uri = None
             self.data = json_encode(data)
             self.save()
Ejemplo n.º 9
0
 def unshare(self):
     if (self.uri != None) and (self.uri != ''):
         conn = Connection(self.uri)
         result = conn.request_delete('', headers={'Accept': 'text/json'})
         if not isValidResponse(result):
             raise Exception(result['body'])
         else:
             data = simplejson.loads(self.data)
             del data['uri']
             self.uri = None
             self.data = json_encode(data)
             self.save()
Ejemplo n.º 10
0
 def __setPlatformUrls(self, metadata):
     conn = Connection(metadata['gadgetResource'] + "/platform")
     body = {
         'PlatformName': ",".join(translate_to_service(metadata['platforms']))
     }
     result = conn.request_post(resource='', body=json_encode(body),
                             headers={'Accept': 'application/json',
                             'Content-Type': 'application/json'})
     if isValidResponse(result):
         gadgets = {}
         platform_list = simplejson.loads(result['body'])
         for platform in platform_list:
             gadgets[platform['PlatformName']]=platform['RedirectUri']
         metadata['gadgets'] = gadgets
     else:
         raise Exception(result['body'])
Ejemplo n.º 11
0
 def share(self):
     if (self.uri == None) or (self.uri == ''):
         conn = Connection(cleanUrl(self.get_catalogue_url()))
         body = self.data
         result = conn.request_post('', body=body, headers={'Accept':'text/json'})
         if isValidResponse(result):
             self.data = result['body']
             obj = simplejson.loads(result['body'])
             self.uri = obj['uri']
             self.save()
         else:
             raise Exception(result['body'])
     else:
         conn = Connection(self.uri)
         result = conn.request_put('', body=self.data, headers={'Accept':'text/json'})
         if not isValidResponse(result):
             raise Exception(result['body'])
Ejemplo n.º 12
0
    def __createResourceURI(self, request, metadata, storage):
        metadata['gadgetResource'] = None
        if isLocalStorage():
            base_uri = request.build_absolute_uri('/static')
            metadata['gadgetUri'] = '/'.join([base_uri, str(storage.pk)])
        else:
            conn = Connection(settings.STORAGE_URL)
            body = {
                'Owner': metadata['owner'],
                'Version': metadata['version'],
                'Author': {
                    'AuthorName': metadata['authorName'],
                    'href': metadata['authorHomepage'],
                    'email': metadata['email']
                },
                'Vendor': {
                    'VendorName': metadata['vendor']
                },
                'GadgetMetadata': {
                    'GadgetName': metadata['name'],
                    'GadgetShortName': metadata['shortname'],
                    'GadgetDescription': metadata['description'],
                    'GadgetIcon': False,
                    'GadgetIconUrl': metadata['imageURI']
                }
            }

            if metadata['height'] != '':
                body['GadgetMetadata']['GadgetDefaultHeight'] = metadata[
                    'height']
            if metadata['width'] != '':
                body['GadgetMetadata']['GadgetDefaultWidth'] = metadata[
                    'width']

            result = conn.request_post(resource='/gadgets/metadata',
                                       body=json_encode(body),
                                       headers={
                                           'Accept': 'application/json',
                                           'Content-Type': 'application/json'
                                       })
            if not isValidResponse(result):
                raise Exception(result['body'])
            data = simplejson.loads(result['body'])
            metadata['gadgetUri'] = data['GadgetLocationURL']
            metadata['gadgetResource'] = data['ServiceGadgetUri']
            metadata['gadgetDataUri'] = data['GadgetDataUri']
Ejemplo n.º 13
0
 def __setPlatformUrls(self, metadata):
     conn = Connection(metadata['gadgetResource'] + "/platform")
     body = {
         'PlatformName':
         ",".join(translate_to_service(metadata['platforms']))
     }
     result = conn.request_post(resource='',
                                body=json_encode(body),
                                headers={
                                    'Accept': 'application/json',
                                    'Content-Type': 'application/json'
                                })
     if isValidResponse(result):
         gadgets = {}
         platform_list = simplejson.loads(result['body'])
         for platform in platform_list:
             gadgets[platform['PlatformName']] = platform['RedirectUri']
         metadata['gadgets'] = gadgets
     else:
         raise Exception(result['body'])
Ejemplo n.º 14
0
    def __createResourceURI(self, request, metadata, storage):
        metadata['gadgetResource'] = None
        if isLocalStorage():
            base_uri = request.build_absolute_uri('/static')
            metadata['gadgetUri'] =  '/'.join([base_uri, str(storage.pk)])
        else:
            conn = Connection(settings.STORAGE_URL)
            body = {
                'Owner': metadata['owner'],
                'Version': metadata['version'],
                'Author':{'AuthorName': metadata['authorName'],
                          'href': metadata['authorHomepage'],
                          'email': metadata['email']
                          },
                'Vendor':{'VendorName': metadata['vendor']},
                'GadgetMetadata':{'GadgetName': metadata['name'],
                                  'GadgetShortName': metadata['shortname'],
                                  'GadgetDescription': metadata['description'],
                                  'GadgetIcon': False,
                                  'GadgetIconUrl': metadata['imageURI']
                                  }
                }

            if metadata['height']!='':
                body['GadgetMetadata']['GadgetDefaultHeight'] = metadata['height']
            if metadata['width']!='':
                body['GadgetMetadata']['GadgetDefaultWidth'] = metadata['width']


            result = conn.request_post(resource='/gadgets/metadata', body=json_encode(body) , headers={'Accept':'application/json', 'Content-Type': 'application/json'})
            if not isValidResponse(result):
                raise Exception(result['body'])
            data = simplejson.loads(result['body'])
            metadata['gadgetUri'] = data['GadgetLocationURL']
            metadata['gadgetResource'] = data['ServiceGadgetUri']
            metadata['gadgetDataUri'] = data['GadgetDataUri']
Ejemplo n.º 15
0
 def __storeGadget(self, gadgetMetaData):
     gadgetPath = path.join(STORAGE_DIR, gadgetMetaData['gadgetRelativePath'])
     gadgetZipFileName = path.join(gadgetPath, STORAGE_GADGET_ZIP_NAME)
     #Remote Storage
     if gadgetMetaData.has_key('gadgetDataUri'):
         conn = Connection(gadgetMetaData['gadgetDataUri'])
         if settings.STORAGE_FORMAT == 'base64string':
             f = open(gadgetZipFileName, 'rb')
             data = f.read()
             f.close()
             data = binascii.b2a_base64(data)
             format = settings.STORAGE_FORMAT
         else:
             data = '/'.join([gadgetMetaData['gadgetUri'], STORAGE_GADGET_ZIP_NAME])
             format = 'URL'
         body = {'Data':data,'DataType':format}
         result = conn.request_post(resource='', body=str(json_encode(body)), headers={'Accept':'application/json', 'Content-Type': 'application/json'})
         if not isValidResponse(result):
             raise Exception(result['body'])
     #Local Storage
     else:
         un = unzip.unzip()
         un.extract(gadgetZipFileName, gadgetPath)
         remove(gadgetZipFileName)
Ejemplo n.º 16
0
 def share(self):
     if (self.uri == None) or (self.uri == ''):
         conn = Connection(cleanUrl(self.get_catalogue_url()))
         body = self.data
         result = conn.request_post('',
                                    body=body,
                                    headers={'Accept': 'text/json'})
         if isValidResponse(result):
             self.data = result['body']
             obj = simplejson.loads(result['body'])
             self.uri = obj['uri']
             self.save()
         else:
             raise Exception(result['body'])
     else:
         conn = Connection(self.uri)
         result = conn.request_put('',
                                   body=self.data,
                                   headers={'Accept': 'text/json'})
         if not isValidResponse(result):
             raise Exception(result['body'])
Ejemplo n.º 17
0
                    bb.save()

            bb.compile_code()
            try:
                print "Sharing %s" % bb.pk
                bb.share()
            except Exception, e:
                print "ERROR sharing: %s" % bb.pk
                print e

        concepts_dir = options["concepts_dir"]
        if concepts_dir:
            if not path.isdir(concepts_dir):
                raise CommandError("'%s' is not a valid directory" % concepts_dir)

            json_pattern = re.compile(r'^.*\.json$')
            for filename in filter(json_pattern.match, os.listdir(concepts_dir)):
                filepath = path.join(concepts_dir, filename)
                print "\nImporting %s..." % filepath,
                f = open(filepath)
                concepts = simplejson.load(f)
                for concept in concepts:
                    conn = Connection(self.concepts_url)
                    body = simplejson.dumps(concept)
                    result = conn.request_post('', body=body, headers={'Accept':'text/json'})
                    if isValidResponse(result):
                        print "OK ",
                    else:
                        print "Error"
                        print result
Ejemplo n.º 18
0
if __name__ == '__main__':
  ip='127.0.0.1'
  print 'pyminifakeDNS:: dom.query. 60 IN A %s' % ip
  
  udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  udps.bind(('127.0.0.1',53))
  
  try:
    while 1:

      data, addr = udps.recvfrom(1024)
      p=DNSQuery(data)

      base_url = "http://dig.jsondns.org/IN/" + p.domain
      conn = Connection(base_url)
      qr = conn.request_get("/A", args={})
      qr2 = qr['body']
      obj = json.loads(qr2)
      obj2 = obj['answer']
      ip = obj2[0][u'rdata']

      udps.sendto(p.request(ip), addr)

      # Write to HOSTS file
      f = open('/etc/hosts', 'a')
      f.write(ip + ' ' + p.domain[:-1] + '\n')
      f.close()

      print 'Request: %s -> %s' % (p.domain, ip)
  except KeyboardInterrupt: