You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. #!/usr/bin/python
  2. import sqlite3
  3. def hash_file(path,hash_if_less,sample):
  4. return _imohash(path,hash_if_less,sample)
  5. def __init_database__(con):
  6. cur = con.cursor()
  7. cur.execute('''CREATE TABLE IF NOT EXISTS `PATHS` (
  8. `PATH` TEXT,
  9. `HASH` BLOB,
  10. `ID` INTEGER)''')
  11. cur.execute('''CREATE TABLE IF NOT EXISTS `BACKUPS` (
  12. `ID` INTEGER,
  13. `HASH_THRESHOLD` INTEGER,
  14. `SAMPLE_SIZE` INTEGER)''')
  15. con.commit()
  16. class fs:
  17. def __init__(self,top,db_path=None,hash_threshold=1024**2,sample_size=128*1024,id=None):
  18. self.top=top
  19. self.hash_threshold=hash_threshold
  20. self.sample_size=sample_size
  21. if db_path is None:
  22. self.db_path = 'fs.db'
  23. else:
  24. self.db_path=db_path
  25. self.con = sqlite3.connect(self.db_path)
  26. __init_database__(self.con)
  27. self.cur = self.con.cursor()
  28. if id is None:
  29. self.cur.execute('SELECT MAX(id) FROM backups')
  30. id=self.cur.fetchone()
  31. if id[0] is None:
  32. self.id = 0
  33. else:
  34. self.id = id[0]+1
  35. else:
  36. self.id = id
  37. def write_to_db(self):
  38. pass
  39. def morph(self,other):
  40. pass
  41. def backup(self,other):
  42. pass
  43. if __name__ == "__main__":
  44. import os
  45. test = fs(os.getcwd())