Exemple #1
0
    def test_file_options(self):
        self.db.close()
        os.unlink(self.filename)

        db = lsm.LSM(self.filename, page_size=1024, block_size=4096)
        self.assertEqual(db.page_size, 1024)
        self.assertEqual(db.block_size, 4096)

        # Page and block cannot be modified after creation.
        def set_page():
            db.page_size = 8192

        def set_block():
            db.block_size = 8192

        self.assertRaises(ValueError, set_page)
        self.assertRaises(ValueError, set_block)

        # We can, however, alter the safety level at any time.
        self.assertEqual(db.write_safety, lsm.SAFETY_NORMAL)
        db.write_safety = lsm.SAFETY_FULL
        self.assertEqual(db.write_safety, lsm.SAFETY_FULL)

        for i in range(10):
            db['k%s' % i] = 'v%s' % i

        self.assertBEqual(db['k0'], 'v0')
        self.assertBEqual(db['k9'], 'v9')
        db.close()

        db2 = lsm.LSM(self.filename,
                      page_size=1024,
                      block_size=4096,
                      mmap=0,
                      transaction_log=False,
                      write_safety=0,
                      multiple_processes=False)
        self.assertEqual(db2.page_size, 1024)
        self.assertEqual(db2.block_size, 4096)
        self.assertEqual(db2.mmap, 0)
        self.assertEqual(db2.transaction_log, 0)
        self.assertEqual(db2.write_safety, 0)
        self.assertEqual(db2.multiple_processes, 0)
        self.assertBEqual(db2['k0'], 'v0')
        self.assertBEqual(db2['k9'], 'v9')
        db2.close()
Exemple #2
0
 def __init__(self, path: str):
     if not os.path.exists(path): os.makedirs(path)
     self.path = path
     self.kv_path = os.path.join(self.path, "kv.ldb")
     self.cedar_path = os.path.join(self.path, 'cedar.dat')
     self.kv = lsm.LSM(self.kv_path)
     self.cedar = pycedar.dict()
     self.cedar.load(self.cedar_path)
Exemple #3
0
def kv(infile):
    if infile.endswith(".gz"): fp = gzip.open(infile, 'rt')
    else: fp = open(infile, 'rt')
    db = lsm.LSM("addrdb/code.ldb")
    lines = fp.read().strip().split("\n")
    pbar = tqdm(total=len(lines))
    for line in lines:
        pbar.update(1)
        item = line.strip().split('\t')
        if len(item) != 2:
            print("err line: %s" % line.strip())
            continue
        db[item[0]] = item[1].split(',')[0]
    pbar.close()
Exemple #4
0
    def test_lsm_info(self):
        self.db.close()

        # Page size is 1KB.
        db = lsm.LSM(self.filename, page_size=1024, autocheckpoint=4)

        w0 = db.pages_written()
        r0 = db.pages_read()
        c0 = db.checkpoint_size()
        self.assertEqual(w0, 0)
        self.assertEqual(r0, 0)
        self.assertEqual(c0, 0)

        data = '0' * 1024
        for i in range(1024):
            db[str(i)] = data
            r = db[str(i)]

        w1 = db.pages_written()
        r1 = db.pages_read()
        c1 = db.checkpoint_size()
        self.assertEqual(w1, 240)
        self.assertEqual(r1, 0)  # Not sure why not increasing...
        self.assertEqual(c1, 956)
Exemple #5
0
 def __init__(self, db_uri: str):
     self.db = lsm.LSM(db_uri)
Exemple #6
0
    config = yaml.load(stream)
    return config


def _get_telegram_bot(bot_key):
    bot = telegram.Bot(token=bot_key)
    return bot


def _is_empty(entry):
    return (not entry.content.strip()
            or entry.content.strip() == entry.username)


config = _read_config("config.yaml")
db = lsm.LSM(config["db"]["filename"])
bot = _get_telegram_bot(config["telegram"]["bot_key"])
my_chat_id = config["telegram"]["chat_id"]

for thread in config['threads']:
    (name, url) = thread.items()[0]
    entries = bct.read_last_page(url)

    for entry in entries:
        if not entry.id in db and not _is_empty(entry):
            message_text =  "= *" + name + "* =========\n" \
            + "[" + entry.username + "|" + entry.userrank + "]\n" \
            + entry.content
            db[entry.id] = "1"
            bot.send_message(chat_id=my_chat_id,
                             text=message_text,
Exemple #7
0
 def __init__(self, filename, readonly=False):
     import lsm
     self.db = lsm.LSM(filename=filename, readonly=readonly)
Exemple #8
0
 def test_no_open(self):
     db = lsm.LSM('test.lsm', open_database=False)
     self.assertFalse(db.is_open)
     self.assertFalse(os.path.exists('test.lsm'))
Exemple #9
0
 def setUp(self):
     self.filename = tempfile.mktemp()
     self.db = lsm.LSM(self.filename)
Exemple #10
0
 def __init__(self, filename, readonly=False):
     import lsm  # from the lsm-db package
     self.db = lsm.LSM(filename=filename, readonly=readonly)
Exemple #11
0
 def __init__(self, path: str):
     if not os.path.exists(path): raise FileNotFoundError(path)
     self.path = path
     self.db = pydict.Dict(self.path)
     self.code2name = lsm.LSM(os.path.join(path, "code.ldb"))