def __init__(self):
     self._conparams = {
         'onep_server': 'm2.exosite.com',
         'onep_port': "80",
         'rpc_url': '/api:v1/rpc/process',
         'http_timeout': 3,
         'datastore_interval': 3
     }
     self._modelparams = {
         'vendor_name': 'intime',
         'model_name': 'intime_gateway'
     }
     self._cik = self._readCIK()
     self._datastore = None
     self._initDataStore()
     self._prov = Provision('http://' + self._conparams["onep_server"] +
                            ':' + self._conparams["onep_port"])
 def __init__(self):
   self._conparams = {'onep_server':'m2.exosite.com','onep_port':"80",'rpc_url':'/api:v1/rpc/process', 'http_timeout':3, 'datastore_interval':3}
   self._modelparams = {'vendor_name':'intime','model_name':'intime_gateway'}
   self._cik = self._readCIK()
   self._datastore = None
   self._initDataStore()
   self._prov = Provision('http://' + self._conparams["onep_server"]
                          + ':' + self._conparams["onep_port"])
class UtilityFunctions():
    #===============================================================================
    def __init__(self):
        self._conparams = {
            'onep_server': 'm2.exosite.com',
            'onep_port': "80",
            'rpc_url': '/api:v1/rpc/process',
            'http_timeout': 3,
            'datastore_interval': 3
        }
        self._modelparams = {
            'vendor_name': 'intime',
            'model_name': 'intime_gateway'
        }
        self._cik = self._readCIK()
        self._datastore = None
        self._initDataStore()
        self._prov = Provision('http://' + self._conparams["onep_server"] +
                               ':' + self._conparams["onep_port"])

#========================== public methods =====================================
#-------------------------------------------------------------------------------

    def getCIK(self):
        return self._cik

    def writeData(self, alias, value):
        try:
            return self._datastore.write(alias, value)
        except:
            pass
#-------------------------------------------------------------------------------

    def readData(self, alias):
        try:
            return self._datastore.read(alias)
        except:
            pass

#-------------------------------------------------------------------------------

    def getModelContent(self, contentname):
        return self._getContent(contentname)

#========================== private methods ====================================
#------------------------------------------------------------------------------

    def _readCIK(self):
        path = ".exosite"
        if os.path.isfile(path):
            try:
                file = open(path)
            except:
                print "CIK file not found"
                return None
            cik = file.read()
            file.close()
            if len(cik) == 40:
                return cik
            else:
                print "Invalid CIK (length)"
                return None
        else:
            print "CIK file not found"
            return None

#------------------------------------------------------------------------------

    def _initDataStore(self):
        transport_config = {
            'host': self._conparams['onep_server'],
            'port': self._conparams['onep_port'],
            'url': self._conparams['rpc_url'],
            'timeout': self._conparams['http_timeout']
        }
        if None != self._cik:
            self._datastore = Datastore(self._cik,
                                        self._conparams['datastore_interval'],
                                        autocreate={
                                            'format': 'integer',
                                            'preprocess': [],
                                            'count': 'infinity',
                                            'duration': 'infinity',
                                            'visibility': 'parent'
                                        },
                                        transport=transport_config)
            self._datastore.start()

#------------------------------------------------------------------------------

    def _getContent(self, contentid):
        return self._prov.content_download(self.getCIK(),
                                           self._modelparams["vendor_name"],
                                           self._modelparams["model_name"],
                                           contentid)
class UtilityFunctions():
#===============================================================================
  def __init__(self):
    self._conparams = {'onep_server':'m2.exosite.com','onep_port':"80",'rpc_url':'/api:v1/rpc/process', 'http_timeout':3, 'datastore_interval':3}
    self._modelparams = {'vendor_name':'intime','model_name':'intime_gateway'}
    self._cik = self._readCIK()
    self._datastore = None
    self._initDataStore()
    self._prov = Provision('http://' + self._conparams["onep_server"]
                           + ':' + self._conparams["onep_port"])

#========================== public methods =====================================
#-------------------------------------------------------------------------------
  def getCIK(self):
    return self._cik

  def writeData(self, alias, value):
    try:
      return self._datastore.write(alias, value)
    except:
      pass
#-------------------------------------------------------------------------------
  def readData(self, alias):
    try:
      return self._datastore.read(alias)
    except:
      pass

#-------------------------------------------------------------------------------
  def getModelContent(self,contentname):
    return self._getContent(contentname)

#========================== private methods ====================================
#------------------------------------------------------------------------------
  def _readCIK(self):
    path = ".exosite"
    if os.path.isfile(path):
      try:
        file = open(path)
      except:
        print "CIK file not found"
        return None
      cik = file.read()
      file.close()
      if len(cik) == 40:
        return cik
      else:
        print "Invalid CIK (length)"
        return None
    else:
      print "CIK file not found"
      return None

#------------------------------------------------------------------------------
  def _initDataStore(self):
    transport_config = {
                        'host':self._conparams['onep_server'],
                        'port':self._conparams['onep_port'],
                        'url': self._conparams['rpc_url'],
                        'timeout':self._conparams['http_timeout']
                       }
    if None != self._cik:
      self._datastore = Datastore(
                                  self._cik,
                                  self._conparams['datastore_interval'],
                                  autocreate={'format':'integer', 'preprocess':[], 'count':'infinity', 'duration':'infinity', 'visibility':'parent'},
                                  transport=transport_config
                                 )
      self._datastore.start()

#------------------------------------------------------------------------------
  def _getContent(self,contentid):
    return self._prov.content_download(
                                       self.getCIK(),
                                       self._modelparams["vendor_name"],
                                       self._modelparams["model_name"],
                                       contentid
                                      )