Пример #1
0
 def test_all_algorithm(self):
     testStr = b'quellochetepare'
     for alg in fsdb.config.ACCEPTED_HASH_ALG:
         mFsdb = Fsdb(os.path.join(self.fsdb_tmp_path, "test_alg"),
                      hash_alg=alg,
                      depth=0)
         digest = mFsdb.add(BytesIO(testStr))
         with mFsdb[digest] as f:
             self.assertEqual(f.read(), testStr)
Пример #2
0
 def test_direct_relative_path(self):
     '''A relative path should be accepted and sanitized'''
     absdir = os.path.dirname(self.fsdb_tmp_path)
     os.chdir(absdir)
     relPath = os.path.relpath(self.fsdb_tmp_path, absdir)
     fsdb = Fsdb(relPath)
     self.assertEqual(fsdb.fsdbRoot, self.fsdb_tmp_path)
Пример #3
0
 def test_deep_retrocompatibility(self):
     conf = fsdb.config.get_defaults()
     conf['deep'] = conf.pop('depth') + 1
     confFile = os.path.join(self.fsdb_tmp_path, Fsdb.CONFIG_FILE)
     fsdb.config.writeConf(confFile, conf)
     myFsdb = Fsdb(self.fsdb_tmp_path)
     self.assertEqual(myFsdb._conf['depth'],
                      fsdb.config.get_defaults()['depth'] + 1)
Пример #4
0
 def test_creation_with_params(self):
     fsdb = Fsdb(self.fsdb_tmp_path,
                 fmode="600",
                 dmode="700",
                 depth=10,
                 hash_alg="sha512")
     self.assertEqual(fsdb._conf['fmode'], int("600", 8))
     self.assertEqual(fsdb._conf['dmode'], int("700", 8))
     self.assertEqual(fsdb._conf['depth'], 10)
     self.assertEqual(fsdb._conf['hash_alg'], "sha512")
Пример #5
0
    def __init__(self, conf={}):
        defaults = {'FSDB_PATH': None, 'ES_HOSTS': None, 'ES_INDEXNAME': None}
        defaults.update(conf)
        self._config = defaults
        log.debug('initializing with this config: ' + dumps(self._config))

        # initialize fsdb
        if self._config['FSDB_PATH']:
            self.__fsdb = Fsdb(self._config['FSDB_PATH'])
        else:
            log.warning(
                'It has not been set any value for FSDB_PATH, file operations will not be supported'
            )

        # initialize elasticsearch
        if not self._config['ES_INDEXNAME']:
            raise ValueError('ES_INDEXNAME cannot be empty')
        self.__db = None
Пример #6
0
def get_aqi24(days):
    dfrom = datetime.now() - timedelta(days=int(days))
    dto = datetime.now()
    db = Fsdb()
    return jsonify(db.getRange(dfrom, dto))
Пример #7
0
 def test_write_default_config(self):
     Fsdb(self.fsdb_tmp_path)
     confFile = os.path.join(self.fsdb_tmp_path, Fsdb.CONFIG_FILE)
     conf = fsdb.config.loadConf(confFile)
     self.assertEqual(conf, fsdb.config.get_defaults())
Пример #8
0
def get_range(sfrom, sto):
    dfrom = datetime.strptime(sfrom, "%Y-%m-%d %H:%M:%S")
    dto = datetime.strptime(sto, "%Y-%m-%d %H:%M:%S")
    db = Fsdb()
    return jsonify(db.getRange(dfrom, dto))
Пример #9
0
 def test_wrong_algorithm(self):
     Fsdb(self.fsdb_tmp_path, hash_alg="verystrangealgorithm")
Пример #10
0
 def test_dmode_passing(self):
     dmode = "700"
     fsdb = Fsdb(self.fsdb_tmp_path, fmode=dmode)
     self.assertEqual(fsdb._conf['dmode'], int(dmode, 8))
Пример #11
0
 def test_fmode_other_session(self):
     fmode = "600"
     Fsdb(self.fsdb_tmp_path, fmode=fmode)
     fsdb = Fsdb(self.fsdb_tmp_path, fmode="000")
     self.assertEqual(fsdb._conf['fmode'], int(fmode, 8))
Пример #12
0
 def test_negative_depth(self):
     Fsdb(self.fsdb_tmp_path, depth=-5, hash_alg="sha1")
Пример #13
0
class FsdbTest(unittest.TestCase):
    
    def setUp(self):
        self.FSDB_TMP_PATH="/tmp/fsdb"
        self.fsdb = Fsdb(self.FSDB_TMP_PATH+"/fsdbRoot")
    
    def createTestFile(self):
        testFilePath = os.path.join(self.FSDB_TMP_PATH,
                                    "testFile_"+randomID(4))
        with open(testFilePath, 'w') as f:
            f.write("test"+randomID(7))
        
        return testFilePath

    def test_creation_without_params(self):
        fsdbRootPath = os.path.join(self.FSDB_TMP_PATH, 
                                    "fsdbRoot_"+randomID(4))
        fsdb = Fsdb(fsdbRootPath)

    def test_creation_with_params(self):
        fsdbRootPath = os.path.join(self.FSDB_TMP_PATH,
                                    "fsdbRoot_"+randomID(4))
        fsdb = Fsdb(fsdbRootPath,
                    mode="0770",
                    deep=5,
                    hash_alg="sha1")

    def test_add(self):
        self.fsdb.add(self.createTestFile())

    def test_file_exists(self):
        testFilePath = self.createTestFile()
        digest = self.fsdb.add(testFilePath)
        self.assertTrue(self.fsdb.exists(digest))

    def test_file_not_exists(self):
        self.assertFalse(self.fsdb.exists(randomID(20)))

    def test_get_file_path(self):
        testFilePath = self.createTestFile()
        digest = self.fsdb.add(testFilePath)
        self.assertIsInstance(self.fsdb.getFilePath(digest),basestring)
        self.assertTrue(os.path.isabs(self.fsdb.getFilePath(digest)))

    def test_same_file_after_retrieval(self):
        testFilePath = self.createTestFile()
        digest = self.fsdb.add(testFilePath)
        storedFilePath = self.fsdb.getFilePath(digest)
        self.assertTrue( filecmp.cmp(testFilePath, storedFilePath, shallow=False) )
        
    def test_remove_existing_file(self):
        testFilePath = self.createTestFile()
        digest = self.fsdb.add(testFilePath)
        self.fsdb.remove(digest)
        
    def test_remove_not_existing_file(self):
        with self.assertRaisesRegexp(OSError,"No such file or directory"):
            self.fsdb.remove(randomID(20))
        
    def tearDown(self):
        shutil.rmtree(self.FSDB_TMP_PATH)
Пример #14
0
 def test_undirect_relative_path(self):
     '''A relative path containing back reference (/../) should be accepted and sanitized'''
     relPath = os.path.relpath(self.fsdb_tmp_path)
     fsdb = Fsdb(relPath)
     self.assertEqual(fsdb.fsdbRoot, self.fsdb_tmp_path)
Пример #15
0
            continue
        # try:
        sp25d = sp_25[0]
        sp25t = sp_25[1]
        sp25v = sp_25[2]
        sp25time = sp25d + " " + sp25t
        if sp25time == sp10time:
            print("Value for " + p10time + " is: " + sp25v)
            return sp25v

        line25 = fppm25.readline()

    fppm25.close()


db = Fsdb()
lasttime = db.lastTime()

line10 = fppm10.readline()
print(line10)

while line10:
    sp_10 = line10.split(" ")
    print("sp10: " + str(sp_10))
    if len(sp_10) != 3:
        line10 = fppm10.readline()
        continue
    sp10time = ""
    sp25v = ""
    sp10v = ""
    # try:
Пример #16
0
def get_rangeFromPl(sfrom):
    dfrom = datetime.strptime(sfrom, "%Y-%m-%d %H:%M:%S")
    dto = sto = datetime.now()  #datetime.strptime(sto, "%Y-%m-%d %H:%M:%S")
    db = Fsdb()
    return jsonify(db.getRangePL(dfrom, dto))
Пример #17
0
 def test_creation_without_params(self):
     Fsdb(self.fsdb_tmp_path)
Пример #18
0
 def setUp(self):
     self.FSDB_TMP_PATH="/tmp/fsdb"
     self.fsdb = Fsdb(self.FSDB_TMP_PATH+"/fsdbRoot")
Пример #19
0
 def setUp(self):
     self.fsdb_tmp_path = tempfile.mkdtemp(prefix="fsdb_test")
     self.fsdb = Fsdb(os.path.join(self.fsdb_tmp_path, "fsdbRoot"))
Пример #20
0
 def test_fmode_passing(self):
     fmode = "600"
     fsdb = Fsdb(self.fsdb_tmp_path, fmode=fmode)
     self.assertEqual(fsdb._conf['fmode'], int(fmode, 8))
Пример #21
0
def writeDb(p10, p25):
    db = Fsdb()
    db.write(p10, p25)
Пример #22
0
def get_lastdaysPl(days):
    db = Fsdb()
    return jsonify(db.getLastDaysPl(days))