Ejemplo n.º 1
0
 def test_missing_and_untracked_files(self):
     database = Database(TEST_LOG_PATH)
     documents = [{
         'name': 'first.txt',
         'type': 'txt',
         'path': 'first.txt'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'images/second.png'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'second.png'
     }]
     for document in documents:
         database.create_document(**document)
     storage = Storage(TEST_ROOT_PATH)
     storage_paths = {'first.txt', 'second.txt', 'third.txt'}
     for path in storage_paths:
         absolute_path = TEST_ROOT_PATH + path
         touch(absolute_path)
     repository = Repository(database, storage)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'second.txt', 'third.txt'})
     missing_files = repository.collect_missing_file_paths()
     self.assertEqual(missing_files, {'second.png', 'images/second.png'})
Ejemplo n.º 2
0
 def test_empty_database_and_storage(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     repository = Repository(database, storage)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(len(untracked_files), 0)
     missing_files = repository.collect_missing_file_paths()
     self.assertEqual(len(missing_files), 0)
Ejemplo n.º 3
0
 def test_untracked_files(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     paths = {'first.txt', 'second.txt', 'third.txt'}
     for path in paths:
         absolute_path = TEST_ROOT_PATH + path
         touch(absolute_path)
     repository = Repository(database, storage)
     untracked_file_paths = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_file_paths, paths)
Ejemplo n.º 4
0
 def test_missing_files(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     documents = [{
         'name': 'first.txt',
         'type': 'txt',
         'path': 'first.txt'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'images/second.png'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'second.png'
     }]
     paths = {'first.txt', 'second.png', 'images/second.png'}
     for document in documents:
         database.create_document(**document)
     repository = Repository(database, storage)
     missing_file_paths = repository.collect_missing_file_paths()
     self.assertEqual(missing_file_paths, paths)
Ejemplo n.º 5
0
 def test_file_tracking(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     paths = {'first.txt', 'second.txt', 'third.txt'}
     for path in paths:
         absolute_path = TEST_ROOT_PATH + path
         touch(absolute_path)
     repository = Repository(database, storage)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files,
                      {'first.txt', 'second.txt', 'third.txt'})
     document_id = repository.track_file('second.txt')
     self.assertEqual(document_id, 1)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'first.txt', 'third.txt'})
     document_id = repository.track_file('third.txt')
     self.assertEqual(document_id, 2)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'first.txt'})
     document_id = repository.track_file('first.txt')
     self.assertEqual(document_id, 3)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, set())
Ejemplo n.º 6
0
from tkinter import ttk
from tkinter import StringVar
from tkinter import messagebox

from grimoire.database import Database
from grimoire.repository import Repository
from grimoire.scope import Scope
from grimoire.storage import Storage

DATABASE_PATH = '/tmp/importer/grimoire.log'
STORAGE_PATH = '/tmp/importer/storage/'
NOTES_PATH = '/tmp/importer/storage/notes/'

database = Database(DATABASE_PATH)
storage = Storage(STORAGE_PATH)
repository = Repository(database, storage)
scope = Scope(database)

if os.path.isdir(NOTES_PATH) is False:
    os.mkdir(NOTES_PATH)


def open_path(file_path):
    absolute_path = os.path.join(storage.path, file_path)
    if not os.path.isfile(absolute_path):
        raise ValueError('Invalid file path! {}'.format(absolute_path))
    extension = os.path.splitext(file_path)[1]
    if len(extension) > 1:
        t = extension[1:].lower()
        if t == 'pdf':
            _ = subprocess.Popen(['evince', absolute_path])
Ejemplo n.º 7
0
 def test_invalid_untrack(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     repository = Repository(database, storage)
     with self.assertRaises(ValueError):
         _ = repository.untrack_document(1234)
Ejemplo n.º 8
0
 def test_invalid_track(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     repository = Repository(database, storage)
     with self.assertRaises(ValueError):
         _ = repository.track_file('invalid/path.error')
Ejemplo n.º 9
0
 def test_track_untrack_and_track_again(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     storage_paths = {'alpha.py', 'beta.py'}
     for path in storage_paths:
         absolute_path = TEST_ROOT_PATH + path
         touch(absolute_path)
     repository = Repository(database, storage)
     for _ in range(1, 10):
         untracked_files = repository.collect_untracked_file_paths()
         self.assertEqual(untracked_files, {'alpha.py', 'beta.py'})
         alpha_id = repository.track_file('alpha.py')
         untracked_files = repository.collect_untracked_file_paths()
         self.assertEqual(untracked_files, {'beta.py'})
         beta_id = repository.track_file('beta.py')
         untracked_files = repository.collect_untracked_file_paths()
         self.assertEqual(untracked_files, set())
         repository.untrack_document(alpha_id)
         untracked_files = repository.collect_untracked_file_paths()
         self.assertEqual(untracked_files, {'alpha.py'})
         repository.untrack_document(beta_id)
Ejemplo n.º 10
0
 def test_document_untracking(self):
     database = Database(TEST_LOG_PATH)
     documents = [{
         'name': 'first.txt',
         'type': 'txt',
         'path': 'first.txt'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'images/second.png'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'second.png'
     }]
     for document in documents:
         database.create_document(**document)
     storage = Storage(TEST_ROOT_PATH)
     storage_paths = {'first.txt', 'images/second.png', 'second.png'}
     os.mkdir(TEST_ROOT_PATH + 'images')
     for path in storage_paths:
         absolute_path = TEST_ROOT_PATH + path
         touch(absolute_path)
     repository = Repository(database, storage)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, set())
     repository.untrack_document(3)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'second.png'})
     repository.untrack_document(1)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'first.txt', 'second.png'})
     repository.untrack_document(2)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files,
                      {'first.txt', 'images/second.png', 'second.png'})