Ejemplo n.º 1
0
 def load_sgf(self, fn):
     content = ""
     if fn :
         path = os.path.join(self.dbhome, fn)
         if FileUtility.fileExists(path):
             content = FileUtility.fileRead(path) 
     return content
Ejemplo n.º 2
0
 def index(self):
     # Every yield line adds one part to the total result body.
     home_page = public.INDEX_PAGE
     if not FileUtility.fileExists(home_page):
             yield "您所访问的页面不存在!"
     if FileUtility.fileSize(home_page) <= 1024:
         content = FileUtility.fileRead( home_page ) 
         if content == None: 
             content = "您所访问的页面不存在!"
         yield content
     else:
         try:
             fp = None
             fp = open(home_page, "rb")
             max_size = FileUtility.fileSize(home_page)
             pos = 0 
             size = 1024
             while pos < max_size: 
                 if pos + size >= max_size:
                     size = max_size - pos
                 content = fp.read(size)
                 yield content
                 pos += size
         except Exception, e:
             pass
         finally:
Ejemplo n.º 3
0
 def initDB(self):
     """
       初始化每个习题集的数据库,不要sqlite的原因如下:
           1)sqlite在cubieboard等板子中速度较慢。
           2)sqlite不支持多线程。
       每个习题集用一个json数据库文件, 文件名用md5归一化,加载前
       先初始化。该数据库文件格式如下:
       {
         sum: xx,
         finish_sum: xx,
         current_num: xx,
         files:{
             <fn1>: { s : 0 | 1,   ## status:0:未完成,1:已完成
                      t1: xxx,     ## start time 开始答题时间,以秒为单位
                      t2: xxx,     ## end time   结束答题时间
                      c : 0 | 1,   ## crypt      0:未加密,1:已加密
                      n : yyy,     ## file index number 题目编号
                      st : xx,     ## 行棋的步骤
                      tr : xx,     ## 尝试的步骤
                      d  : 0 | 1   ## 是否看了答案
                    },  
             <fn2>: { s : 0 | 1,   ## status
                      t1: xxx,     ## start time
                      t2: xxx,     ## end time
                      c : 0 | 1,   ## crypt
                      n : yyy,     ## file index number
                      st : xx,     ## 行棋的步骤
                      tr : xx,     ## 尝试的步骤
                      d  : 0 | 1   ## 是否看了答案
                    },  
             ....
         }
       }
     """
     if FileUtility.fileExists(self.dbfile): return True
     db = {}
     files = {}
     count  = 0
     finish = 0
     current= 0
     for fn in self.sgf_db.list_dir():
         crypt = self.is_sgf_file(fn)
         if None == crypt: continue
         files[fn] = {}
         files[fn]['c'] = crypt ## crypt
         files[fn]['s'] = 0     ## status
         files[fn]['t1']= 0     ## start time
         files[fn]['t2']= 0     ## end time
         files[fn]['n'] = count ## fn index
         count += 1
     db['sum']        = count
     db['finish_sum'] = finish 
     db['current_num']= current 
     db['files']      = files
     self.saveDB(self.dbfile, db)
     del db
Ejemplo n.º 4
0
 def __init__(self, dbfile=None):
     if dbfile != None:
         self.dbfile = dbfile 
     else:
         self.dbfile = public.DB_FILE 
     if not FileUtility.fileExists(self.dbfile):
         FileUtility.createFile(self.dbfile)
     self.conn = None
     self.cursor = None
     self.conn_failed = False