def saveOrderInfo(self,inOrderInfo):
        try:
            logger = getLogger()
            logger.debug("start saveOrderInfo")
            ret = True
            ret &= self.compareOrderInfo(inOrderInfo)

            #all condition is ok
            if(ret):
                ret = DbModule.saveData2Db(inOrderInfo)

                if (ret):
                    ret = DbModule.saveData2DbSqlite("GWImp"+inOrderInfo["orderId"])
        except :
            logger.error("exception occur, see the traceback.log")
            #异常写入日志文件.
            f = open('traceback.txt','a')
            traceback.print_exc()
            traceback.print_exc(file = f)
            f.flush()
            f.close()
        else:
            pass
        finally:
            pass
            return ret
Example #2
0
def GetDbNames(user='******',password='******',dirName='.',dBase='::template1',cn=None):
  """ returns a list of databases that are available

    **Arguments**

      - user: the username for DB access

      - password: the password to be used for DB access

    **Returns**

      - a list of db names (strings)

  """
  if DbModule.getDbSql:
    if not cn:
      try:
        cn = DbModule.connect(dBase,user,password)
      except:
        print 'Problems opening database: %s'%(dBase)
        return []
    c = cn.cursor()
    c.execute(DbModule.getDbSql)
    if RDConfig.usePgSQL:
      names = ['::'+str(x[0]) for x in c.fetchall()]
    else:
      names = ['::'+str(x[0]) for x in c.fetchall()]
    names.remove(dBase)
  elif DbModule.fileWildcard:
    import os.path,glob
    names = glob.glob(os.path.join(dirName,DbModule.fileWildcard))
  else:
    names = []
  return names
def job_function():
    try:
        logger = getLogger()
        logger.debug("start job function")

        logger.debug("start get mailid")
        lstOrderid = DbModule.getData4DbSqlite()

        for strOrderid in lstOrderid:
            strHeaderIndex = strOrderid.find('GWImp')
            strOrderidSearch = strOrderid
            # first got it.
            if (strHeaderIndex == 0):
                strOrderidSearch = strOrderid[len('GWImp'):len(strOrderid)]
            orderTransInfos = getOrderTrans(strOrderidSearch)

            strMailid = orderTransInfos['mailid']
            strCompanytile = orderTransInfos['companytitle']

	    logger.debug("get orderTransInfo from REST success.")

            if (strMailid is not None) & (strMailid != "") & (strCompanytile is not None) & (strCompanytile != ""):
                logger.debug("start callwebservice")
                returnStatus = deliverySend(strOrderidSearch,strCompanytile,strMailid)
                #if return success,delete the record.
                if (returnStatus == '5'):
                    logger.debug("delete record")
                    DbModule.delData4DbSqlite(strOrderid)

                pass
    except :
        logger.error("exception occur, see the traceback.log")
        #异常写入日志文件.
        f = open('traceback.txt','a')
        traceback.print_exc()
        traceback.print_exc(file = f)
        f.flush()
        f.close()
    else:
        pass
    finally:
        pass
Example #4
0
  def GetCursor(self):
    """ returns a cursor for direct manipulation of the DB
      only one cursor is available

    """
    if self.cursor is not None:
      return self.cursor
      
    self.cn = DbModule.connect(self.dbName,self.user,self.password)
    self.cursor = self.cn.cursor()
    return self.cursor
Example #5
0
def GetColumnNames(dBase,
                   table,
                   user='******',
                   password='******',
                   join='',
                   what='*',
                   cn=None):
    """ gets a list of columns available in a DB table

    **Arguments**

      - dBase: the name of the DB file to be used

      - table: the name of the table to query

      - user: the username for DB access

      - password: the password to be used for DB access

      - join: an optional join clause  (omit the verb 'join')

      - what: an optional clause indicating what to select

    **Returns**

      -  a list of column names

  """
    if not cn:
        cn = DbModule.connect(dBase, user, password)
    c = cn.cursor()
    cmd = 'select %s from %s' % (what, table)
    if join:
        if join.strip().find('join') != 0:
            join = 'join %s' % (join)
        cmd += ' ' + join
    c.execute(cmd)
    c.fetchone()
    desc = c.description
    res = map(lambda x: str(x[0]), desc)
    return res
Example #6
0
def GetColumnNamesAndTypes(dBase,
                           table,
                           user='******',
                           password='******',
                           join='',
                           what='*',
                           cn=None):
    """ gets a list of columns available in a DB table along with their types

    **Arguments**

      - dBase: the name of the DB file to be used

      - table: the name of the table to query

      - user: the username for DB access

      - password: the password to be used for DB access

      - join: an optional join clause (omit the verb 'join')

      - what: an optional clause indicating what to select

    **Returns**

      - a list of 2-tuples containing:

          1) column name

          2) column type

  """
    if not cn:
        cn = DbModule.connect(dBase, user, password)
    c = cn.cursor()
    cmd = 'select %s from %s' % (what, table)
    if join:
        cmd += ' join %s' % (join)
    c.execute(cmd)
    return GetColumnInfoFromCursor(c)
Example #7
0
def GetTableNames(dBase,
                  user='******',
                  password='******',
                  includeViews=0,
                  cn=None):
    """ returns a list of tables available in a database

    **Arguments**

      - dBase: the name of the DB file to be used

      - user: the username for DB access

      - password: the password to be used for DB access

      - includeViews: if this is non-null, the views in the db will
        also be returned

    **Returns**

      - a list of table names (strings)

  """
    if not cn:
        try:
            cn = DbModule.connect(dBase, user, password)
        except:
            print 'Problems opening database: %s' % (dBase)
            return []
    c = cn.cursor()
    if not includeViews:
        comm = DbModule.getTablesSql
    else:
        comm = DbModule.getTablesAndViewsSql
    c.execute(comm)
    names = [str(x[0]).upper() for x in c.fetchall()]
    if RDConfig.usePgSQL and 'PG_LOGDIR_LS' in names:
        names.remove('PG_LOGDIR_LS')
    return names
Example #8
0
def GetDbNames(user='******',
               password='******',
               dirName='.',
               dBase='::template1',
               cn=None):
    """ returns a list of databases that are available

    **Arguments**

      - user: the username for DB access

      - password: the password to be used for DB access

    **Returns**

      - a list of db names (strings)

  """
    if DbModule.getDbSql:
        if not cn:
            try:
                cn = DbModule.connect(dBase, user, password)
            except:
                print 'Problems opening database: %s' % (dBase)
                return []
        c = cn.cursor()
        c.execute(DbModule.getDbSql)
        if RDConfig.usePgSQL:
            names = ['::' + str(x[0]) for x in c.fetchall()]
        else:
            names = ['::' + str(x[0]) for x in c.fetchall()]
        names.remove(dBase)
    elif DbModule.fileWildcard:
        import os.path, glob
        names = glob.glob(os.path.join(dirName, DbModule.fileWildcard))
    else:
        names = []
    return names
Example #9
0
def GetTableNames(dBase,user='******',password='******',
                  includeViews=0,cn=None):
  """ returns a list of tables available in a database

    **Arguments**

      - dBase: the name of the DB file to be used

      - user: the username for DB access

      - password: the password to be used for DB access

      - includeViews: if this is non-null, the views in the db will
        also be returned

    **Returns**

      - a list of table names (strings)

  """
  if not cn:
    try:
      cn = DbModule.connect(dBase,user,password)
    except:
      print 'Problems opening database: %s'%(dBase)
      return []
  c = cn.cursor()
  if not includeViews:
    comm = DbModule.getTablesSql
  else:
    comm = DbModule.getTablesAndViewsSql
  c.execute(comm)
  names = [str(x[0]).upper() for x in c.fetchall()]
  if RDConfig.usePgSQL and 'PG_LOGDIR_LS' in names:
    names.remove('PG_LOGDIR_LS')
  return names
Example #10
0
def GetColumnNames(dBase,table,user='******',password='******',
                   join='',what='*',cn=None):
  """ gets a list of columns available in a DB table

    **Arguments**

      - dBase: the name of the DB file to be used

      - table: the name of the table to query

      - user: the username for DB access

      - password: the password to be used for DB access

      - join: an optional join clause  (omit the verb 'join')

      - what: an optional clause indicating what to select

    **Returns**

      -  a list of column names

  """
  if not cn:
    cn = DbModule.connect(dBase,user,password)
  c = cn.cursor()
  cmd = 'select %s from %s'%(what,table)
  if join:
    if join.strip().find('join') != 0:
      join = 'join %s'%(join)
    cmd +=' ' + join
  c.execute(cmd)
  c.fetchone()
  desc = c.description
  res = map(lambda x:str(x[0]),desc)
  return res
Example #11
0
def GetColumnNamesAndTypes(dBase,table,
                           user='******',password='******',
                           join='',what='*',cn=None):
  """ gets a list of columns available in a DB table along with their types

    **Arguments**

      - dBase: the name of the DB file to be used

      - table: the name of the table to query

      - user: the username for DB access

      - password: the password to be used for DB access

      - join: an optional join clause (omit the verb 'join')

      - what: an optional clause indicating what to select

    **Returns**

      - a list of 2-tuples containing:

          1) column name

          2) column type

  """
  if not cn:
    cn = DbModule.connect(dBase,user,password)
  c = cn.cursor()
  cmd = 'select %s from %s'%(what,table)
  if join:
    cmd += ' join %s'%(join)
  c.execute(cmd)
  return GetColumnInfoFromCursor(c)
 def getTransInfo(self,inOrderId):
     logger = getLogger()
     logger.debug("start getTransInfo")
     return DbModule.getOrderTransInfo(inOrderId)