Cosmit
This commit is contained in:
parent
0dd51aff58
commit
81f2661593
@ -52,16 +52,17 @@ def _open(path, mode):
|
|||||||
else:
|
else:
|
||||||
return open(system_path(path), mode, encoding='utf-8')
|
return open(system_path(path), mode, encoding='utf-8')
|
||||||
|
|
||||||
|
|
||||||
def check_file(path, fail=True):
|
def check_file(path, fail=True):
|
||||||
syspath = system_path(path)
|
syspath = system_path(path)
|
||||||
return (_check_system_path_exists(syspath, fail=fail)
|
return (_check_system_path_exists(syspath, fail=fail) and
|
||||||
and _check_system_path_is(u'isfile', syspath, fail=fail))
|
_check_system_path_is(u'isfile', syspath, fail=fail))
|
||||||
|
|
||||||
|
|
||||||
def check_directory(path, fail=True):
|
def check_directory(path, fail=True):
|
||||||
syspath = system_path(path)
|
syspath = system_path(path)
|
||||||
return (_check_system_path_exists(syspath, fail=fail)
|
return (_check_system_path_exists(syspath, fail=fail) and
|
||||||
and _check_system_path_is(u'isdir', syspath, fail=fail))
|
_check_system_path_is(u'isdir', syspath, fail=fail))
|
||||||
|
|
||||||
|
|
||||||
def read_text_file(filepath, fail=True):
|
def read_text_file(filepath, fail=True):
|
||||||
@ -79,6 +80,7 @@ def read_text_file(filepath, fail=True):
|
|||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def read_binary_file(filepath, fail=True):
|
def read_binary_file(filepath, fail=True):
|
||||||
check_file(filepath, fail=fail)
|
check_file(filepath, fail=fail)
|
||||||
with _open(filepath, 'rb') as f:
|
with _open(filepath, 'rb') as f:
|
||||||
|
@ -13,7 +13,7 @@ def filter_filename(filename, ext):
|
|||||||
""" Return the filename without the extension if the extension matches ext.
|
""" Return the filename without the extension if the extension matches ext.
|
||||||
Otherwise return None
|
Otherwise return None
|
||||||
"""
|
"""
|
||||||
pattern ='.*\{}$'.format(ext)
|
pattern = '.*\{}$'.format(ext)
|
||||||
if re.match(pattern, filename) is not None:
|
if re.match(pattern, filename) is not None:
|
||||||
return filename[:-len(ext)]
|
return filename[:-len(ext)]
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ else:
|
|||||||
# for test_usecase.
|
# for test_usecase.
|
||||||
def _get_raw_stdout():
|
def _get_raw_stdout():
|
||||||
return sys.stdout.buffer
|
return sys.stdout.buffer
|
||||||
|
|
||||||
def _get_raw_stderr():
|
def _get_raw_stderr():
|
||||||
return sys.stderr.buffer
|
return sys.stderr.buffer
|
||||||
|
|
||||||
|
15
pubs/repo.py
15
pubs/repo.py
@ -110,8 +110,9 @@ class Repository(object):
|
|||||||
self.databroker.remove_note(citekey, self.conf['main']['note_extension'],
|
self.databroker.remove_note(citekey, self.conf['main']['note_extension'],
|
||||||
silent=True)
|
silent=True)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass # FIXME: if IOError is about being unable to
|
# FIXME: if IOError is about being unable to
|
||||||
# remove the file, we need to issue an error.
|
# remove the file, we need to issue an error.
|
||||||
|
pass
|
||||||
self.citekeys.remove(citekey)
|
self.citekeys.remove(citekey)
|
||||||
self.databroker.remove(citekey)
|
self.databroker.remove(citekey)
|
||||||
|
|
||||||
@ -126,16 +127,18 @@ class Repository(object):
|
|||||||
p.docpath = None
|
p.docpath = None
|
||||||
self.push_paper(p, overwrite=True, event=False)
|
self.push_paper(p, overwrite=True, event=False)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass # FIXME: if IOError is about being unable to
|
# FIXME: if IOError is about being unable to
|
||||||
# remove the file, we need to issue an error.I
|
# remove the file, we need to issue an error.I
|
||||||
|
pass
|
||||||
|
|
||||||
def pull_docpath(self, citekey):
|
def pull_docpath(self, citekey):
|
||||||
try:
|
try:
|
||||||
p = self.pull_paper(citekey)
|
p = self.pull_paper(citekey)
|
||||||
return self.databroker.real_docpath(p.docpath)
|
return self.databroker.real_docpath(p.docpath)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass # FIXME: if IOError is about being unable to
|
# FIXME: if IOError is about being unable to
|
||||||
# remove the file, we need to issue an error.I
|
# remove the file, we need to issue an error.I
|
||||||
|
pass
|
||||||
|
|
||||||
def rename_paper(self, paper, new_citekey=None, old_citekey=None):
|
def rename_paper(self, paper, new_citekey=None, old_citekey=None):
|
||||||
if old_citekey is None:
|
if old_citekey is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user