Import is working
* Various bugfixes * Bugfix with utf-8
This commit is contained in:
parent
915e9de9ad
commit
c757b1cb64
@ -110,6 +110,7 @@ Here are some sources of inspirations for this project :
|
||||
|
||||
A list of ideas and TODO. Don't hesitate to give feedback on the ones you really want or to propose your owns.
|
||||
|
||||
50. Anti-duplicate ?
|
||||
65. Look for published version in arXiv
|
||||
70. No DOI for HAL => metadata with SOAP API… don't want to handle it for now :/
|
||||
80. Search engine
|
||||
@ -118,10 +119,10 @@ A list of ideas and TODO. Don't hesitate to give feedback on the ones you really
|
||||
|
||||
## Issues ?
|
||||
|
||||
* Remove the watermarks on pdf files => done, some warning in okular on generated pdf, but seems ok. Seems to be a bug in Okular.
|
||||
|
||||
* Multiplication of {{}}
|
||||
|
||||
## Thanks
|
||||
|
||||
* Nathan Grigg for his [arxiv2bib](https://pypi.python.org/pypi/arxiv2bib/1.0.5#downloads) python module
|
||||
* François Boulogne for his [python-bibtexparser](https://github.com/sciunto/python-bibtexparser) python module and his integration of new requested features
|
||||
* pyparsing [search parser example](http://pyparsing.wikispaces.com/file/view/searchparser.py)
|
||||
|
15
backend.py
15
backend.py
@ -47,7 +47,7 @@ def getNewName(src, bibtex, tag=''):
|
||||
tools.warning("Unable to create tag dir " +
|
||||
params.folder+tag+".")
|
||||
|
||||
new_name = (params.folder + tools.slugify(tag) +
|
||||
new_name = (params.folder + tools.slugify(tag) + '/' +
|
||||
tools.slugify(new_name) + tools.getExtension(src))
|
||||
|
||||
return new_name
|
||||
@ -256,6 +256,11 @@ def getEntries():
|
||||
|
||||
|
||||
def updateArXiv(entry):
|
||||
"""Look for new versions of arXiv entry `entry`
|
||||
|
||||
Returns False if no new versions or not an arXiv entry,
|
||||
Updates the file and returns the new bibtex otherwise.
|
||||
"""
|
||||
bibtex = getBibtex(entry)
|
||||
# Check arXiv
|
||||
if('ArchivePrefix' not in bibtex and
|
||||
@ -280,3 +285,11 @@ def updateArXiv(entry):
|
||||
return last_bibtex
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def search(query):
|
||||
"""Performs a search in the bibtex index.
|
||||
|
||||
Param: query is a dict of keys and the query for these keys
|
||||
"""
|
||||
raise Exception('TODO')
|
||||
|
29
main.py
29
main.py
@ -21,7 +21,8 @@ EDITOR = os.environ.get('EDITOR') if os.environ.get('EDITOR') else 'vim'
|
||||
def checkBibtex(filename, bibtex):
|
||||
print("The bibtex entry found for "+filename+" is:")
|
||||
|
||||
bibtex = BibTexParser(bibtex, customization=homogeneize_latex_encoding)
|
||||
bibtex = BibTexParser(bibtex.encode('utf-8'),
|
||||
customization=homogeneize_latex_encoding)
|
||||
bibtex = bibtex.get_entry_dict()
|
||||
if len(bibtex) > 0:
|
||||
bibtex_name = bibtex.keys()[0]
|
||||
@ -31,18 +32,22 @@ def checkBibtex(filename, bibtex):
|
||||
bibtex_string = ''
|
||||
print(bibtex_string)
|
||||
check = tools.rawInput("Is it correct? [Y/n] ")
|
||||
old_filename = bibtex['file']
|
||||
try:
|
||||
old_filename = bibtex['file']
|
||||
except:
|
||||
old_filename = False
|
||||
|
||||
while check.lower() == 'n':
|
||||
with tempfile.NamedTemporaryFile(suffix=".tmp") as tmpfile:
|
||||
tmpfile.write(bibtex_string)
|
||||
tmpfile.write(bibtex_string.encode('utf-8'))
|
||||
tmpfile.flush()
|
||||
subprocess.call([EDITOR, tmpfile.name])
|
||||
bibtex = BibTexParser(tmpfile.read()+"\n",
|
||||
tmpfile.seek(0)
|
||||
bibtex = BibTexParser(tmpfile.read().encode('utf-8')+"\n",
|
||||
customization=homogeneize_latex_encoding)
|
||||
|
||||
bibtex = bibtex.get_entry_dict()
|
||||
if 'file' not in bibtex:
|
||||
if old_filename is not False and 'file' not in bibtex:
|
||||
tools.warning("Invalid bibtex entry. No filename given.")
|
||||
tools.rawInput("Press Enter to go back to editor.")
|
||||
check = 'n'
|
||||
@ -56,7 +61,7 @@ def checkBibtex(filename, bibtex):
|
||||
print("\nThe bibtex entry for "+filename+" is:")
|
||||
print(bibtex_string)
|
||||
check = tools.rawInput("Is it correct? [Y/n] ")
|
||||
if old_filename != bibtex['file']:
|
||||
if old_filename is not False and old_filename != bibtex['file']:
|
||||
try:
|
||||
shutil.move(old_filename, bibtex['file'])
|
||||
except:
|
||||
@ -206,7 +211,7 @@ def editEntry(entry, file_id='both'):
|
||||
|
||||
try:
|
||||
with open(params.folder+'index.bib', 'r') as fh:
|
||||
index = BibTexParser(fh.read(),
|
||||
index = BibTexParser(fh.read().encode('utf-8'),
|
||||
customization=homogeneize_latex_encoding)
|
||||
index = index.get_entry_dict()
|
||||
except:
|
||||
@ -225,7 +230,7 @@ def downloadFile(url, filetype, manual):
|
||||
tmp = tempfile.NamedTemporaryFile(suffix='.'+contenttype)
|
||||
|
||||
with open(tmp.name, 'w+') as fh:
|
||||
fh.write(dl)
|
||||
fh.write(dl.encode('utf-8'))
|
||||
new_name = addFile(tmp.name, filetype, manual)
|
||||
tmp.close()
|
||||
return new_name
|
||||
@ -237,7 +242,7 @@ def downloadFile(url, filetype, manual):
|
||||
def openFile(ident):
|
||||
try:
|
||||
with open(params.folder+'index.bib', 'r') as fh:
|
||||
bibtex = BibTexParser(fh.read(),
|
||||
bibtex = BibTexParser(fh.read().encode('utf-8'),
|
||||
customization=homogeneize_latex_encoding)
|
||||
bibtex = bibtex.get_entry_dict()
|
||||
except:
|
||||
@ -410,6 +415,12 @@ if __name__ == '__main__':
|
||||
help="a filename or an identifier")
|
||||
parser_update.set_defaults(func='update')
|
||||
|
||||
parser_search = subparsers.add_parser('search', help="search help")
|
||||
# TODO: Check
|
||||
parser_delete.add_argument('query', metavar='entry', nargs='+',
|
||||
help="your query, see README for more info.")
|
||||
parser_search.set_defaults(func='search')
|
||||
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
if args.func == 'download':
|
||||
|
5
tools.py
5
tools.py
@ -39,12 +39,13 @@ def replaceAll(text, dic):
|
||||
def rawInput(string):
|
||||
"""Flush stdin and then prompt the user for something"""
|
||||
tcflush(sys.stdin, TCIOFLUSH)
|
||||
return raw_input(string)
|
||||
return raw_input(string).decode('utf-8')
|
||||
|
||||
|
||||
def warning(*objs):
|
||||
"""Write warnings to stderr"""
|
||||
print("WARNING: ", *objs, file=sys.stderr)
|
||||
printed = [i.encode('utf-8') for i in objs]
|
||||
print("WARNING: ", *printed, file=sys.stderr)
|
||||
|
||||
|
||||
def listDir(path):
|
||||
|
Loading…
Reference in New Issue
Block a user