backtracked on changes. repo is passing all tests
This commit is contained in:
parent
9614593192
commit
3c0f575b92
@ -136,9 +136,23 @@ class Repository(object):
|
|||||||
and new_citekey in self):
|
and new_citekey in self):
|
||||||
raise CiteKeyCollision('citekey {} already in use'.format(
|
raise CiteKeyCollision('citekey {} already in use'.format(
|
||||||
new_citekey))
|
new_citekey))
|
||||||
|
|
||||||
self.remove_paper(paper.citekey, remove_doc = False)
|
self.remove_paper(paper.citekey, remove_doc = False)
|
||||||
|
old_citekey = paper.citekey
|
||||||
paper.citekey = new_citekey
|
paper.citekey = new_citekey
|
||||||
self.add_paper(paper, overwrite = overwrite)
|
self.add_paper(paper, overwrite = overwrite)
|
||||||
|
self._move_doc(old_citekey, paper)
|
||||||
|
|
||||||
|
def _move_doc(self, old_citekey, paper):
|
||||||
|
"""Fragile. Make more robust"""
|
||||||
|
try:
|
||||||
|
old_docfile = self.find_document(old_citekey)
|
||||||
|
ext = os.path.splitext(old_docfile)[1]
|
||||||
|
new_docfile = os.path.join(self.doc_dir, paper.citekey + ext)
|
||||||
|
shutil.move(old_docfile, new_docfile)
|
||||||
|
paper.set_external_document(new_docfile)
|
||||||
|
except NoDocumentFile:
|
||||||
|
pass
|
||||||
|
|
||||||
def _bibfile(self, citekey):
|
def _bibfile(self, citekey):
|
||||||
return os.path.join(self.bib_dir, citekey + '.bibyaml')
|
return os.path.join(self.bib_dir, citekey + '.bibyaml')
|
||||||
@ -176,14 +190,21 @@ class Repository(object):
|
|||||||
if not citekey + _base27(n) in self.citekeys:
|
if not citekey + _base27(n) in self.citekeys:
|
||||||
return citekey + _base27(n)
|
return citekey + _base27(n)
|
||||||
|
|
||||||
|
def find_document(self, citekey):
|
||||||
|
found = glob.glob('{}/{}.*'.format(self.doc_dir, citekey))
|
||||||
|
if found:
|
||||||
|
return found[0]
|
||||||
|
else:
|
||||||
|
raise NoDocumentFile
|
||||||
|
|
||||||
def import_document(self, citekey, doc_file):
|
def import_document(self, citekey, doc_file):
|
||||||
if citekey not in self.citekeys:
|
if citekey not in self.citekeys:
|
||||||
raise ValueError("Unknown citekey {}.".format(citekey))
|
raise(ValueError, "Unknown citekey: %s." % citekey)
|
||||||
else:
|
else:
|
||||||
if not os.path.isfile(doc_file):
|
if not os.path.isfile(doc_file):
|
||||||
raise ValueError("No file {} found.".format(doc_file))
|
raise ValueError("No file {} found.".format(doc_file))
|
||||||
new_doc_file = os.path.join(self.doc_dir,
|
ext = os.path.splitext(doc_file)[1]
|
||||||
os.path.basename(doc_file))
|
new_doc_file = os.path.join(self.doc_dir, citekey + ext)
|
||||||
shutil.copy(doc_file, new_doc_file)
|
shutil.copy(doc_file, new_doc_file)
|
||||||
|
|
||||||
def get_tags(self):
|
def get_tags(self):
|
||||||
|
@ -101,7 +101,7 @@ class TestUpdatePaper(TestRepo):
|
|||||||
os.path.join(os.path.dirname(__file__),
|
os.path.join(os.path.dirname(__file__),
|
||||||
'data/pagerank.pdf'))
|
'data/pagerank.pdf'))
|
||||||
self.repo.rename_paper(self.repo.get_paper('Turing1950'), 'Doe2003')
|
self.repo.rename_paper(self.repo.get_paper('Turing1950'), 'Doe2003')
|
||||||
# self.assertFalse(os.path.exists(os.path.join(
|
self.assertFalse(os.path.exists(os.path.join(
|
||||||
# self.repo.doc_dir, 'Turing1950.pdf')))
|
self.repo.doc_dir, 'Turing1950.pdf')))
|
||||||
# self.assertTrue(os.path.exists(os.path.join(
|
self.assertTrue(os.path.exists(os.path.join(
|
||||||
# self.repo.doc_dir, 'Doe2013.pdf')))
|
self.repo.doc_dir, 'Doe2003.pdf')))
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import sys, os
|
import sys, os, shutil, glob
|
||||||
import unittest
|
import unittest
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
|
||||||
import testenv
|
import testenv
|
||||||
import fake_filesystem
|
import fake_filesystem
|
||||||
import fake_filesystem_shutil
|
import fake_filesystem_shutil
|
||||||
|
import fake_filesystem_glob
|
||||||
|
|
||||||
from papers import papers_cmd
|
from papers import papers_cmd
|
||||||
from papers import color
|
from papers import color
|
||||||
@ -12,23 +13,27 @@ from papers.p3 import io
|
|||||||
|
|
||||||
real_os = os
|
real_os = os
|
||||||
real_open = open
|
real_open = open
|
||||||
|
real_shutil = shutil
|
||||||
|
real_glob = glob
|
||||||
|
|
||||||
fake_os, fake_open, fake_shutil = None, None, None
|
fake_os, fake_open, fake_shutil, fake_glob = None, None, None, None
|
||||||
|
|
||||||
def _create_fake_fs():
|
def _create_fake_fs():
|
||||||
global fake_os, fake_open, fake_shutil
|
global fake_os, fake_open, fake_shutil, fake_glob
|
||||||
|
|
||||||
fake_fs = fake_filesystem.FakeFilesystem()
|
fake_fs = fake_filesystem.FakeFilesystem()
|
||||||
fake_os = fake_filesystem.FakeOsModule(fake_fs)
|
fake_os = fake_filesystem.FakeOsModule(fake_fs)
|
||||||
fake_open = fake_filesystem.FakeFileOpen(fake_fs)
|
fake_open = fake_filesystem.FakeFileOpen(fake_fs)
|
||||||
fake_shutil = fake_filesystem_shutil.FakeShutilModule(fake_fs)
|
fake_shutil = fake_filesystem_shutil.FakeShutilModule(fake_fs)
|
||||||
|
fake_glob = fake_filesystem_glob.FakeGlobModule(fake_fs)
|
||||||
|
|
||||||
fake_fs.CreateDirectory(fake_os.path.expanduser('~'))
|
fake_fs.CreateDirectory(fake_os.path.expanduser('~'))
|
||||||
__builtins__['open'] = fake_open
|
__builtins__['open'] = fake_open
|
||||||
__builtins__['file'] = fake_open
|
__builtins__['file'] = fake_open
|
||||||
|
|
||||||
sys.modules['os'] = fake_os
|
sys.modules['os'] = fake_os
|
||||||
sys.modules['shutil'] = fake_shutil
|
sys.modules['shutil'] = fake_shutil
|
||||||
|
sys.modules['glob'] = fake_glob
|
||||||
|
|
||||||
import papers
|
import papers
|
||||||
for importer, modname, ispkg in pkgutil.walk_packages(
|
for importer, modname, ispkg in pkgutil.walk_packages(
|
||||||
@ -102,7 +107,7 @@ class TestAdd(unittest.TestCase):
|
|||||||
|
|
||||||
papers_cmd.execute('papers init -p /not_default'.split())
|
papers_cmd.execute('papers init -p /not_default'.split())
|
||||||
papers_cmd.execute('papers add -b /data/pagerank.bib -d /data/pagerank.pdf'.split())
|
papers_cmd.execute('papers add -b /data/pagerank.bib -d /data/pagerank.pdf'.split())
|
||||||
self.assertEqual(set(fake_os.listdir('/not_default/doc')), {'pagerank.pdf'})
|
self.assertEqual(set(fake_os.listdir('/not_default/doc')), {'Page99.pdf'})
|
||||||
|
|
||||||
|
|
||||||
class TestList(unittest.TestCase):
|
class TestList(unittest.TestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user