Updated conf
This commit is contained in:
parent
bc15f86057
commit
6be5cb3f16
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,8 +5,6 @@
|
|||||||
*~
|
*~
|
||||||
.*.sw*
|
.*.sw*
|
||||||
|
|
||||||
params.py
|
|
||||||
translation-server
|
|
||||||
*.pdf
|
*.pdf
|
||||||
*.bib
|
*.bib
|
||||||
*.djvu
|
*.djvu
|
||||||
|
11
arxiv2bib.py
11
arxiv2bib.py
@ -184,8 +184,7 @@ class Reference(object):
|
|||||||
("Month", self.month),
|
("Month", self.month),
|
||||||
("Note", self.note),
|
("Note", self.note),
|
||||||
("Url", self.url),
|
("Url", self.url),
|
||||||
("File", self.id + ".pdf"),
|
("File", self.id + ".pdf")]:
|
||||||
]:
|
|
||||||
if len(v):
|
if len(v):
|
||||||
lines.append("%-13s = {%s}" % (k, v))
|
lines.append("%-13s = {%s}" % (k, v))
|
||||||
|
|
||||||
@ -203,12 +202,12 @@ class ReferenceErrorInfo(object):
|
|||||||
|
|
||||||
def bibtex(self):
|
def bibtex(self):
|
||||||
"""BibTeX comment explaining error"""
|
"""BibTeX comment explaining error"""
|
||||||
return "@comment{%(id)s: %(message)s}" % \
|
return ("@comment{%(id)s: %(message)s}" %
|
||||||
{'id': self.id, 'message': self.message}
|
{'id': self.id, 'message': self.message})
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Error: %(message)s (%(id)s)" % \
|
return ("Error: %(message)s (%(id)s)" %
|
||||||
{'id': self.id, 'message': self.message}
|
{'id': self.id, 'message': self.message})
|
||||||
|
|
||||||
|
|
||||||
def arxiv2bib(id_list):
|
def arxiv2bib(id_list):
|
||||||
|
54
backend.py
54
backend.py
@ -14,21 +14,21 @@ import os
|
|||||||
import re
|
import re
|
||||||
import tools
|
import tools
|
||||||
import fetcher
|
import fetcher
|
||||||
import params
|
|
||||||
from bibtexparser.bparser import BibTexParser
|
from bibtexparser.bparser import BibTexParser
|
||||||
|
from config import config
|
||||||
from codecs import open
|
from codecs import open
|
||||||
|
|
||||||
|
|
||||||
def getNewName(src, bibtex, tag='', override_format=None):
|
def getNewName(src, bibtex, tag='', override_format=None):
|
||||||
"""
|
"""
|
||||||
Return the formatted name according to params for the given
|
Return the formatted name according to config for the given
|
||||||
bibtex entry
|
bibtex entry
|
||||||
"""
|
"""
|
||||||
authors = re.split(' and ', bibtex['author'])
|
authors = re.split(' and ', bibtex['author'])
|
||||||
|
|
||||||
if bibtex['type'] == 'article':
|
if bibtex['type'] == 'article':
|
||||||
if override_format is None:
|
if override_format is None:
|
||||||
new_name = params.format_articles
|
new_name = config.get("format_articles")
|
||||||
else:
|
else:
|
||||||
new_name = override_format
|
new_name = override_format
|
||||||
try:
|
try:
|
||||||
@ -37,7 +37,7 @@ def getNewName(src, bibtex, tag='', override_format=None):
|
|||||||
pass
|
pass
|
||||||
elif bibtex['type'] == 'book':
|
elif bibtex['type'] == 'book':
|
||||||
if override_format is None:
|
if override_format is None:
|
||||||
new_name = params.format_books
|
new_name = config.get("format_books")
|
||||||
else:
|
else:
|
||||||
new_name = override_format
|
new_name = override_format
|
||||||
|
|
||||||
@ -53,25 +53,27 @@ def getNewName(src, bibtex, tag='', override_format=None):
|
|||||||
if('archiveprefix' in bibtex and
|
if('archiveprefix' in bibtex and
|
||||||
'arXiv' in bibtex['archiveprefix']):
|
'arXiv' in bibtex['archiveprefix']):
|
||||||
new_name = new_name.replace("%v",
|
new_name = new_name.replace("%v",
|
||||||
'-'+bibtex['eprint'][bibtex['eprint'].rfind('v'):])
|
'-' +
|
||||||
|
bibtex['eprint'][bibtex['eprint'].
|
||||||
|
rfind('v'):])
|
||||||
else:
|
else:
|
||||||
new_name = new_name.replace("%v", '')
|
new_name = new_name.replace("%v", '')
|
||||||
|
|
||||||
for custom in params.format_custom:
|
for custom in config.get("format_custom"):
|
||||||
new_name = custom(new_name)
|
new_name = custom(new_name)
|
||||||
|
|
||||||
if tag == '':
|
if tag == '':
|
||||||
new_name = (params.folder + tools.slugify(new_name) +
|
new_name = (config.get("folder") + tools.slugify(new_name) +
|
||||||
tools.getExtension(src))
|
tools.getExtension(src))
|
||||||
else:
|
else:
|
||||||
if not os.path.isdir(params.folder + tag):
|
if not os.path.isdir(config.get("folder") + tag):
|
||||||
try:
|
try:
|
||||||
os.mkdir(params.folder + tag)
|
os.mkdir(config.get("folder") + tag)
|
||||||
except:
|
except:
|
||||||
tools.warning("Unable to create tag dir " +
|
tools.warning("Unable to create tag dir " +
|
||||||
params.folder+tag+".")
|
config.get("folder")+tag+".")
|
||||||
|
|
||||||
new_name = (params.folder + tools.slugify(tag) + '/' +
|
new_name = (config.get("folder") + tools.slugify(tag) + '/' +
|
||||||
tools.slugify(new_name) + tools.getExtension(src))
|
tools.slugify(new_name) + tools.getExtension(src))
|
||||||
|
|
||||||
return new_name
|
return new_name
|
||||||
@ -83,7 +85,8 @@ def bibtexAppend(data):
|
|||||||
data is a dict for one entry in bibtex, as the one from bibtexparser output
|
data is a dict for one entry in bibtex, as the one from bibtexparser output
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'a', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'a', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
fh.write(tools.parsed2Bibtex(data)+"\n")
|
fh.write(tools.parsed2Bibtex(data)+"\n")
|
||||||
except:
|
except:
|
||||||
tools.warning("Unable to open index file.")
|
tools.warning("Unable to open index file.")
|
||||||
@ -94,7 +97,8 @@ def bibtexEdit(ident, modifs):
|
|||||||
"""Update ident key in bibtex file, modifications are in modifs dict"""
|
"""Update ident key in bibtex file, modifications are in modifs dict"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
bibtex = BibTexParser(fh.read())
|
bibtex = BibTexParser(fh.read())
|
||||||
bibtex = bibtex.get_entry_dict()
|
bibtex = bibtex.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
@ -115,7 +119,8 @@ def bibtexRewrite(data):
|
|||||||
for entry in data.keys():
|
for entry in data.keys():
|
||||||
bibtex += tools.parsed2Bibtex(data[entry])+"\n"
|
bibtex += tools.parsed2Bibtex(data[entry])+"\n"
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'w', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'w', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
fh.write(bibtex)
|
fh.write(bibtex)
|
||||||
except:
|
except:
|
||||||
tools.warning("Unable to open index file.")
|
tools.warning("Unable to open index file.")
|
||||||
@ -125,7 +130,8 @@ def bibtexRewrite(data):
|
|||||||
def deleteId(ident):
|
def deleteId(ident):
|
||||||
"""Delete a file based on its id in the bibtex file"""
|
"""Delete a file based on its id in the bibtex file"""
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
bibtex = BibTexParser(fh.read().decode('utf-8'))
|
bibtex = BibTexParser(fh.read().decode('utf-8'))
|
||||||
bibtex = bibtex.get_entry_dict()
|
bibtex = bibtex.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
@ -160,7 +166,8 @@ def deleteId(ident):
|
|||||||
def deleteFile(filename):
|
def deleteFile(filename):
|
||||||
"""Delete a file based on its filename"""
|
"""Delete a file based on its filename"""
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
bibtex = BibTexParser(fh.read().decode('utf-8'))
|
bibtex = BibTexParser(fh.read().decode('utf-8'))
|
||||||
bibtex = bibtex.get_entry_dict()
|
bibtex = bibtex.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
@ -206,10 +213,11 @@ def diffFilesIndex():
|
|||||||
* full bibtex entry with file='' if file is not found
|
* full bibtex entry with file='' if file is not found
|
||||||
* only file entry if file with missing bibtex entry
|
* only file entry if file with missing bibtex entry
|
||||||
"""
|
"""
|
||||||
files = tools.listDir(params.folder)
|
files = tools.listDir(config.get("folder"))
|
||||||
files = [i for i in files if tools.getExtension(i) in ['.pdf', '.djvu']]
|
files = [i for i in files if tools.getExtension(i) in ['.pdf', '.djvu']]
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
index = BibTexParser(fh.read())
|
index = BibTexParser(fh.read())
|
||||||
index_diff = index.get_entry_dict()
|
index_diff = index.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
@ -233,10 +241,11 @@ def getBibtex(entry, file_id='both', clean=False):
|
|||||||
|
|
||||||
entry is either a filename or a bibtex ident
|
entry is either a filename or a bibtex ident
|
||||||
file_id is file or id or both to search for a file / id / both
|
file_id is file or id or both to search for a file / id / both
|
||||||
clean is to clean the ignored fields specified in params
|
clean is to clean the ignored fields specified in config
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
bibtex = BibTexParser(fh.read())
|
bibtex = BibTexParser(fh.read())
|
||||||
bibtex = bibtex.get_entry_dict()
|
bibtex = bibtex.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
@ -256,7 +265,7 @@ def getBibtex(entry, file_id='both', clean=False):
|
|||||||
bibtex_entry = bibtex[key]
|
bibtex_entry = bibtex[key]
|
||||||
break
|
break
|
||||||
if clean:
|
if clean:
|
||||||
for field in params.ignore_fields:
|
for field in config.get("ignore_fields"):
|
||||||
try:
|
try:
|
||||||
del(bibtex_entry[field])
|
del(bibtex_entry[field])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -267,7 +276,8 @@ def getBibtex(entry, file_id='both', clean=False):
|
|||||||
def getEntries():
|
def getEntries():
|
||||||
"""Returns the list of all entries in the bibtex index"""
|
"""Returns the list of all entries in the bibtex index"""
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
bibtex = BibTexParser(fh.read())
|
bibtex = BibTexParser(fh.read())
|
||||||
bibtex = bibtex.get_entry_dict()
|
bibtex = bibtex.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
|
38
bmc.py
38
bmc.py
@ -11,9 +11,9 @@ import backend
|
|||||||
import fetcher
|
import fetcher
|
||||||
import tearpages
|
import tearpages
|
||||||
import tools
|
import tools
|
||||||
import params
|
|
||||||
from bibtexparser.bparser import BibTexParser
|
from bibtexparser.bparser import BibTexParser
|
||||||
from codecs import open
|
from codecs import open
|
||||||
|
from config import config
|
||||||
|
|
||||||
EDITOR = os.environ.get('EDITOR') if os.environ.get('EDITOR') else 'vim'
|
EDITOR = os.environ.get('EDITOR') if os.environ.get('EDITOR') else 'vim'
|
||||||
|
|
||||||
@ -116,9 +116,11 @@ def addFile(src, filetype, manual, autoconfirm, tag):
|
|||||||
tools.warning("Could not determine the DOI nor the arXiv id nor " +
|
tools.warning("Could not determine the DOI nor the arXiv id nor " +
|
||||||
"the ISBN for "+src+". Switching to manual entry.")
|
"the ISBN for "+src+". Switching to manual entry.")
|
||||||
doi_arxiv_isbn = ''
|
doi_arxiv_isbn = ''
|
||||||
while doi_arxiv_isbn not in ['doi', 'arxiv', 'isbn', 'manual', 'skip']:
|
while(doi_arxiv_isbn not in
|
||||||
doi_arxiv_isbn = tools.rawInput("DOI / arXiv " +
|
['doi', 'arxiv', 'isbn', 'manual', 'skip']):
|
||||||
"/ ISBN / manual / skip? ").lower()
|
doi_arxiv_isbn = (tools.rawInput("DOI / arXiv " +
|
||||||
|
"/ ISBN / manual / skip? ").
|
||||||
|
lower())
|
||||||
if doi_arxiv_isbn == 'doi':
|
if doi_arxiv_isbn == 'doi':
|
||||||
doi = tools.rawInput('DOI? ')
|
doi = tools.rawInput('DOI? ')
|
||||||
elif doi_arxiv_isbn == 'arxiv':
|
elif doi_arxiv_isbn == 'arxiv':
|
||||||
@ -132,7 +134,8 @@ def addFile(src, filetype, manual, autoconfirm, tag):
|
|||||||
src+", switching to manual entry.")
|
src+", switching to manual entry.")
|
||||||
doi_arxiv = ''
|
doi_arxiv = ''
|
||||||
while doi_arxiv not in ['doi', 'arxiv', 'manual', 'skip']:
|
while doi_arxiv not in ['doi', 'arxiv', 'manual', 'skip']:
|
||||||
doi_arxiv = tools.rawInput("DOI / arXiv / manual / skip? ").lower()
|
doi_arxiv = (tools.rawInput("DOI / arXiv / manual / skip? ").
|
||||||
|
lower())
|
||||||
if doi_arxiv == 'doi':
|
if doi_arxiv == 'doi':
|
||||||
doi = tools.rawInput('DOI? ')
|
doi = tools.rawInput('DOI? ')
|
||||||
elif doi_arxiv == 'arxiv':
|
elif doi_arxiv == 'arxiv':
|
||||||
@ -144,7 +147,9 @@ def addFile(src, filetype, manual, autoconfirm, tag):
|
|||||||
while isbn_manual not in ['isbn', 'manual', 'skip']:
|
while isbn_manual not in ['isbn', 'manual', 'skip']:
|
||||||
isbn_manual = tools.rawInput("ISBN / manual / skip? ").lower()
|
isbn_manual = tools.rawInput("ISBN / manual / skip? ").lower()
|
||||||
if isbn_manual == 'isbn':
|
if isbn_manual == 'isbn':
|
||||||
isbn = tools.rawInput('ISBN? ').replace(' ', '').replace('-', '')
|
isbn = (tools.rawInput('ISBN? ').
|
||||||
|
replace(' ', '').
|
||||||
|
replace('-', ''))
|
||||||
elif isbn_manual == 'skip':
|
elif isbn_manual == 'skip':
|
||||||
return False
|
return False
|
||||||
elif doi is not False:
|
elif doi is not False:
|
||||||
@ -200,7 +205,8 @@ def addFile(src, filetype, manual, autoconfirm, tag):
|
|||||||
shutil.copy2(src, new_name)
|
shutil.copy2(src, new_name)
|
||||||
except IOError:
|
except IOError:
|
||||||
new_name = False
|
new_name = False
|
||||||
sys.exit("Unable to move file to library dir " + params.folder+".")
|
sys.exit("Unable to move file to library dir " +
|
||||||
|
config.get("folder")+".")
|
||||||
|
|
||||||
# Remove first page of IOP papers
|
# Remove first page of IOP papers
|
||||||
try:
|
try:
|
||||||
@ -258,7 +264,8 @@ def editEntry(entry, file_id='both'):
|
|||||||
os.path.dirname(bibtex['file']))
|
os.path.dirname(bibtex['file']))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
index = BibTexParser(fh.read())
|
index = BibTexParser(fh.read())
|
||||||
index = index.get_entry_dict()
|
index = index.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
@ -292,7 +299,8 @@ def downloadFile(url, filetype, manual, autoconfirm, tag):
|
|||||||
|
|
||||||
def openFile(ident):
|
def openFile(ident):
|
||||||
try:
|
try:
|
||||||
with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh:
|
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||||
|
as fh:
|
||||||
bibtex = BibTexParser(fh.read())
|
bibtex = BibTexParser(fh.read())
|
||||||
bibtex = bibtex.get_entry_dict()
|
bibtex = bibtex.get_entry_dict()
|
||||||
except:
|
except:
|
||||||
@ -363,7 +371,7 @@ def resync():
|
|||||||
except IOError:
|
except IOError:
|
||||||
new_name = False
|
new_name = False
|
||||||
sys.exit("Unable to move file to library dir " +
|
sys.exit("Unable to move file to library dir " +
|
||||||
params.folder+".")
|
config.get("folder")+".")
|
||||||
backend.bibtexEdit(entry['id'], {'file': filename})
|
backend.bibtexEdit(entry['id'], {'file': filename})
|
||||||
else:
|
else:
|
||||||
print("Found file without any associated entry in index:")
|
print("Found file without any associated entry in index:")
|
||||||
@ -388,12 +396,12 @@ def resync():
|
|||||||
print(entry['file'] + " removed from disk and " +
|
print(entry['file'] + " removed from disk and " +
|
||||||
"index.")
|
"index.")
|
||||||
# Check for empty tag dirs
|
# Check for empty tag dirs
|
||||||
for i in os.listdir(params.folder):
|
for i in os.listdir(config.get("folder")):
|
||||||
if os.path.isdir(i) and not os.listdir(params.folder + i):
|
if os.path.isdir(i) and not os.listdir(config.get("folder") + i):
|
||||||
try:
|
try:
|
||||||
os.rmdir(params.folder + i)
|
os.rmdir(config.get("folder") + i)
|
||||||
except:
|
except:
|
||||||
tools.warning("Found empty tag dir "+params.folder + i +
|
tools.warning("Found empty tag dir "+config.get("folder") + i +
|
||||||
" but could not delete it.")
|
" but could not delete it.")
|
||||||
|
|
||||||
|
|
||||||
@ -584,7 +592,7 @@ if __name__ == '__main__':
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif args.func == 'list':
|
elif args.func == 'list':
|
||||||
listPapers = tools.listDir(params.folder)
|
listPapers = tools.listDir(config.get("folder"))
|
||||||
listPapers.sort()
|
listPapers.sort()
|
||||||
|
|
||||||
for paper in listPapers:
|
for paper in listPapers:
|
||||||
|
81
config.py
Normal file
81
config.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import os
|
||||||
|
import errno
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import tools
|
||||||
|
|
||||||
|
# List of available options :
|
||||||
|
# * folder : folder in which papers are stored
|
||||||
|
# * proxies : list of proxies to use, e.g. ['', "socks5://localhost:4711"]
|
||||||
|
# * format_articles, format_books : masks to rename files
|
||||||
|
# * format_custom : list of lambda functions to apply to rename files.
|
||||||
|
# E.g. : format_custom = [lambda x: x.replace('test', 'some_expr')]
|
||||||
|
# * ignore_fields : list of fields to ignore when returning bibtex
|
||||||
|
|
||||||
|
# Available masks to rename files are
|
||||||
|
# %f = last name of first author
|
||||||
|
# %l = last name of last author
|
||||||
|
# %j = name of the journal
|
||||||
|
# %Y = published year
|
||||||
|
# %t = title
|
||||||
|
# %a = authors
|
||||||
|
# %v = arXiv version (e.g. '-v1') or nothing if not an arXiv paper
|
||||||
|
|
||||||
|
|
||||||
|
def make_sure_path_exists(path):
|
||||||
|
try:
|
||||||
|
os.makedirs(path)
|
||||||
|
return True
|
||||||
|
except OSError as exception:
|
||||||
|
if exception.errno != errno.EEXIST:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class Config():
|
||||||
|
def __init__(self):
|
||||||
|
self.config_path = os.path.expanduser("~/.config/")
|
||||||
|
self.config = {}
|
||||||
|
self.load()
|
||||||
|
|
||||||
|
def get(self, param):
|
||||||
|
return self.config[param]
|
||||||
|
|
||||||
|
def set(self, param, value):
|
||||||
|
self.config[param] = value
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
self.set("folder", os.path.expanduser("~/Papers/"))
|
||||||
|
self.set("proxies", [''])
|
||||||
|
self.set("format_articles", "%f_%l-%j-%Y%v")
|
||||||
|
self.set("format_books", "%a-%t")
|
||||||
|
self.set("format_custom", [])
|
||||||
|
self.set("ignore_fields", ["file", "doi", "tag"])
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
try:
|
||||||
|
initialized = make_sure_path_exists(self.config_path)
|
||||||
|
except:
|
||||||
|
tools.warning("Unable to create ~/.config folder.")
|
||||||
|
sys.exit(1)
|
||||||
|
if not initialized:
|
||||||
|
self.initialize()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
with open(self.config_path + "bmc.json", 'r') as fh:
|
||||||
|
self.config = json.load(fh)
|
||||||
|
except (ValueError, IOError):
|
||||||
|
tools.warning("Config file could not be read.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
try:
|
||||||
|
with open(self.config_path + "bmc.json", 'r') as fh:
|
||||||
|
fh.write(json.dumps(self.config))
|
||||||
|
except IOError:
|
||||||
|
tools.warning("Could not write config file.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
config = Config()
|
@ -17,8 +17,8 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import arxiv2bib as arxiv_metadata
|
import arxiv2bib as arxiv_metadata
|
||||||
import tools
|
import tools
|
||||||
import params
|
|
||||||
from bibtexparser.bparser import BibTexParser
|
from bibtexparser.bparser import BibTexParser
|
||||||
|
from config import config
|
||||||
from isbntools.dev._fmt import fmtbib
|
from isbntools.dev._fmt import fmtbib
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ def download(url):
|
|||||||
available proxies sequentially. Returns the raw content of the file, or
|
available proxies sequentially. Returns the raw content of the file, or
|
||||||
false if it could not be downloaded.
|
false if it could not be downloaded.
|
||||||
"""
|
"""
|
||||||
for proxy in params.proxies:
|
for proxy in config.get("proxies"):
|
||||||
r_proxy = {
|
r_proxy = {
|
||||||
"http": proxy,
|
"http": proxy,
|
||||||
"https": proxy,
|
"https": proxy,
|
||||||
@ -150,8 +150,9 @@ def findDOI(src):
|
|||||||
extractDOI = doi_re.search(extractfull.lower().replace('Œ', '-'))
|
extractDOI = doi_re.search(extractfull.lower().replace('Œ', '-'))
|
||||||
if not extractDOI:
|
if not extractDOI:
|
||||||
# PNAS fix
|
# PNAS fix
|
||||||
extractDOI = doi_pnas_re.search(extractfull.lower().replace('pnas',
|
extractDOI = doi_pnas_re.search(extractfull.
|
||||||
'/pnas'))
|
lower().
|
||||||
|
replace('pnas', '/pnas'))
|
||||||
if not extractDOI:
|
if not extractDOI:
|
||||||
# JSB fix
|
# JSB fix
|
||||||
extractDOI = doi_jsb_re.search(extractfull.lower())
|
extractDOI = doi_jsb_re.search(extractfull.lower())
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
# -*- coding: utf8 -*-
|
|
||||||
|
|
||||||
# The folder in which the papers should be stored
|
|
||||||
folder = "/home/phyks/Papers/"
|
|
||||||
|
|
||||||
if folder[-1] != '/':
|
|
||||||
folder = folder+'/'
|
|
||||||
|
|
||||||
# The various proxies available to retrieve the content
|
|
||||||
proxies = [
|
|
||||||
'',
|
|
||||||
'socks5://localhost:4711'
|
|
||||||
]
|
|
||||||
|
|
||||||
# The mask to rename files
|
|
||||||
# %f = last name of first author
|
|
||||||
# %l = last name of last author
|
|
||||||
# %j = name of the journal
|
|
||||||
# %Y = published year
|
|
||||||
# %t = title
|
|
||||||
# %a = authors
|
|
||||||
# %v = arXiv version (e.g. '-v1') or nothing if not an arXiv paper
|
|
||||||
format_articles = "%f_%l-%j-%Y%v"
|
|
||||||
format_books = "%a-%t"
|
|
||||||
|
|
||||||
# Other customization
|
|
||||||
# List of lambda functions to apply
|
|
||||||
# E.g. : format_custom = [lambda x: x.replace('test', 'some_expr')]
|
|
||||||
format_custom = []
|
|
||||||
|
|
||||||
# Fields to ignore when exporting Bibtex entries
|
|
||||||
ignore_fields = ['file', 'doi', 'tag']
|
|
@ -11,6 +11,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from backend import *
|
from backend import *
|
||||||
from bibtexparser.bparser import BibTexParser
|
from bibtexparser.bparser import BibTexParser
|
||||||
|
from config import config
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -18,7 +19,7 @@ import tempfile
|
|||||||
|
|
||||||
class TestFetcher(unittest.TestCase):
|
class TestFetcher(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
params.folder = tempfile.mkdtemp()+"/"
|
config.set("folder", tempfile.mkdtemp()+"/")
|
||||||
self.bibtex_article_string = """
|
self.bibtex_article_string = """
|
||||||
@article{1303.3130v1,
|
@article{1303.3130v1,
|
||||||
abstract={We study the role of the dipolar interaction, correctly accounting for the
|
abstract={We study the role of the dipolar interaction, correctly accounting for the
|
||||||
@ -59,57 +60,57 @@ Lattice},
|
|||||||
|
|
||||||
def test_getNewName_article(self):
|
def test_getNewName_article(self):
|
||||||
self.assertEqual(getNewName("test.pdf", self.bibtex_article),
|
self.assertEqual(getNewName("test.pdf", self.bibtex_article),
|
||||||
params.folder+"N_Bartolo_A_Recati-j-2013-v1.pdf")
|
config.get("folder")+"N_Bartolo_A_Recati-j-2013-v1.pdf")
|
||||||
|
|
||||||
def test_getNewName_article_override(self):
|
def test_getNewName_article_override(self):
|
||||||
self.assertEqual(getNewName("test.pdf", self.bibtex_article, override_format="%f"),
|
self.assertEqual(getNewName("test.pdf", self.bibtex_article, override_format="%f"),
|
||||||
params.folder+"N_Bartolo.pdf")
|
config.get("folder")+"N_Bartolo.pdf")
|
||||||
|
|
||||||
def test_getNewName_book(self):
|
def test_getNewName_book(self):
|
||||||
self.assertEqual(getNewName("test.pdf", self.bibtex_book),
|
self.assertEqual(getNewName("test.pdf", self.bibtex_book),
|
||||||
params.folder+"C_J_Pethick_H_Smith-Bose-Einstein_Condensation_In_Dilute_Gases.pdf")
|
config.get("folder")+"C_J_Pethick_H_Smith-Bose-Einstein_Condensation_In_Dilute_Gases.pdf")
|
||||||
|
|
||||||
def test_getNewName_book_override(self):
|
def test_getNewName_book_override(self):
|
||||||
self.assertEqual(getNewName("test.pdf", self.bibtex_book, override_format="%a"),
|
self.assertEqual(getNewName("test.pdf", self.bibtex_book, override_format="%a"),
|
||||||
params.folder+"C_J_Pethick_H_Smith.pdf")
|
config.get("folder")+"C_J_Pethick_H_Smith.pdf")
|
||||||
|
|
||||||
def test_bibtexAppend(self):
|
def test_bibtexAppend(self):
|
||||||
bibtexAppend(self.bibtex_article)
|
bibtexAppend(self.bibtex_article)
|
||||||
with open(params.folder+'index.bib', 'r') as fh:
|
with open(config.get("folder")+'index.bib', 'r') as fh:
|
||||||
self.assertEqual(fh.read(),
|
self.assertEqual(fh.read(),
|
||||||
'@article{1303.3130v1,\n\tabstract={We study the role of the dipolar interaction, correctly accounting for the\nDipolar-Induced Resonance (DIR), in a quasi-one-dimensional system of ultracold\nbosons. We first show how the DIR affects the lowest-energy states of two\nparticles in a harmonic trap. Then, we consider a deep optical lattice loaded\nwith ultracold dipolar bosons. We describe this many-body system using an\natom-dimer extended Bose-Hubbard model. We analyze the impact of the DIR on the\nphase diagram at T=0 by exact diagonalization of a small-sized system. In\nparticular, the resonance strongly modifies the range of parameters for which a\nmass density wave should occur.},\n\tarchiveprefix={arXiv},\n\tauthor={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},\n\teprint={1303.3130v1},\n\tfile={/home/phyks/Papers/N_Bartolo_A_Recati-j-2013.pdf},\n\tlink={http://arxiv.org/abs/1303.3130v1},\n\tmonth={Mar},\n\tprimaryclass={cond-mat.quant-gas},\n\ttag={},\n\ttitle={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical\nLattice},\n\tyear={2013},\n}\n\n\n')
|
'@article{1303.3130v1,\n\tabstract={We study the role of the dipolar interaction, correctly accounting for the\nDipolar-Induced Resonance (DIR), in a quasi-one-dimensional system of ultracold\nbosons. We first show how the DIR affects the lowest-energy states of two\nparticles in a harmonic trap. Then, we consider a deep optical lattice loaded\nwith ultracold dipolar bosons. We describe this many-body system using an\natom-dimer extended Bose-Hubbard model. We analyze the impact of the DIR on the\nphase diagram at T=0 by exact diagonalization of a small-sized system. In\nparticular, the resonance strongly modifies the range of parameters for which a\nmass density wave should occur.},\n\tarchiveprefix={arXiv},\n\tauthor={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},\n\teprint={1303.3130v1},\n\tfile={/home/phyks/Papers/N_Bartolo_A_Recati-j-2013.pdf},\n\tlink={http://arxiv.org/abs/1303.3130v1},\n\tmonth={Mar},\n\tprimaryclass={cond-mat.quant-gas},\n\ttag={},\n\ttitle={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical\nLattice},\n\tyear={2013},\n}\n\n\n')
|
||||||
|
|
||||||
def test_bibtexEdit(self):
|
def test_bibtexEdit(self):
|
||||||
bibtexAppend(self.bibtex_article)
|
bibtexAppend(self.bibtex_article)
|
||||||
bibtexEdit(self.bibtex_article['id'], {'id': 'bidule'})
|
bibtexEdit(self.bibtex_article['id'], {'id': 'bidule'})
|
||||||
with open(params.folder+'index.bib', 'r') as fh:
|
with open(config.get("folder")+'index.bib', 'r') as fh:
|
||||||
self.assertEqual(fh.read(),
|
self.assertEqual(fh.read(),
|
||||||
'@article{bidule,\n\tabstract={We study the role of the dipolar interaction, correctly accounting for the\nDipolar-Induced Resonance (DIR), in a quasi-one-dimensional system of ultracold\nbosons. We first show how the DIR affects the lowest-energy states of two\nparticles in a harmonic trap. Then, we consider a deep optical lattice loaded\nwith ultracold dipolar bosons. We describe this many-body system using an\natom-dimer extended Bose-Hubbard model. We analyze the impact of the DIR on the\nphase diagram at T=0 by exact diagonalization of a small-sized system. In\nparticular, the resonance strongly modifies the range of parameters for which a\nmass density wave should occur.},\n\tarchiveprefix={arXiv},\n\tauthor={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},\n\teprint={1303.3130v1},\n\tfile={/home/phyks/Papers/N_Bartolo_A_Recati-j-2013.pdf},\n\tlink={http://arxiv.org/abs/1303.3130v1},\n\tmonth={Mar},\n\tprimaryclass={cond-mat.quant-gas},\n\ttag={},\n\ttitle={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical\nLattice},\n\tyear={2013},\n}\n\n\n')
|
'@article{bidule,\n\tabstract={We study the role of the dipolar interaction, correctly accounting for the\nDipolar-Induced Resonance (DIR), in a quasi-one-dimensional system of ultracold\nbosons. We first show how the DIR affects the lowest-energy states of two\nparticles in a harmonic trap. Then, we consider a deep optical lattice loaded\nwith ultracold dipolar bosons. We describe this many-body system using an\natom-dimer extended Bose-Hubbard model. We analyze the impact of the DIR on the\nphase diagram at T=0 by exact diagonalization of a small-sized system. In\nparticular, the resonance strongly modifies the range of parameters for which a\nmass density wave should occur.},\n\tarchiveprefix={arXiv},\n\tauthor={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},\n\teprint={1303.3130v1},\n\tfile={/home/phyks/Papers/N_Bartolo_A_Recati-j-2013.pdf},\n\tlink={http://arxiv.org/abs/1303.3130v1},\n\tmonth={Mar},\n\tprimaryclass={cond-mat.quant-gas},\n\ttag={},\n\ttitle={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical\nLattice},\n\tyear={2013},\n}\n\n\n')
|
||||||
|
|
||||||
def test_bibtexRewrite(self):
|
def test_bibtexRewrite(self):
|
||||||
bibtexAppend(self.bibtex_book)
|
bibtexAppend(self.bibtex_book)
|
||||||
bibtexRewrite({0: self.bibtex_article})
|
bibtexRewrite({0: self.bibtex_article})
|
||||||
with open(params.folder+'index.bib', 'r') as fh:
|
with open(config.get("folder")+'index.bib', 'r') as fh:
|
||||||
self.assertEqual(fh.read(),
|
self.assertEqual(fh.read(),
|
||||||
'@article{1303.3130v1,\n\tabstract={We study the role of the dipolar interaction, correctly accounting for the\nDipolar-Induced Resonance (DIR), in a quasi-one-dimensional system of ultracold\nbosons. We first show how the DIR affects the lowest-energy states of two\nparticles in a harmonic trap. Then, we consider a deep optical lattice loaded\nwith ultracold dipolar bosons. We describe this many-body system using an\natom-dimer extended Bose-Hubbard model. We analyze the impact of the DIR on the\nphase diagram at T=0 by exact diagonalization of a small-sized system. In\nparticular, the resonance strongly modifies the range of parameters for which a\nmass density wave should occur.},\n\tarchiveprefix={arXiv},\n\tauthor={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},\n\teprint={1303.3130v1},\n\tfile={/home/phyks/Papers/N_Bartolo_A_Recati-j-2013.pdf},\n\tlink={http://arxiv.org/abs/1303.3130v1},\n\tmonth={Mar},\n\tprimaryclass={cond-mat.quant-gas},\n\ttag={},\n\ttitle={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical\nLattice},\n\tyear={2013},\n}\n\n\n')
|
'@article{1303.3130v1,\n\tabstract={We study the role of the dipolar interaction, correctly accounting for the\nDipolar-Induced Resonance (DIR), in a quasi-one-dimensional system of ultracold\nbosons. We first show how the DIR affects the lowest-energy states of two\nparticles in a harmonic trap. Then, we consider a deep optical lattice loaded\nwith ultracold dipolar bosons. We describe this many-body system using an\natom-dimer extended Bose-Hubbard model. We analyze the impact of the DIR on the\nphase diagram at T=0 by exact diagonalization of a small-sized system. In\nparticular, the resonance strongly modifies the range of parameters for which a\nmass density wave should occur.},\n\tarchiveprefix={arXiv},\n\tauthor={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},\n\teprint={1303.3130v1},\n\tfile={/home/phyks/Papers/N_Bartolo_A_Recati-j-2013.pdf},\n\tlink={http://arxiv.org/abs/1303.3130v1},\n\tmonth={Mar},\n\tprimaryclass={cond-mat.quant-gas},\n\ttag={},\n\ttitle={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical\nLattice},\n\tyear={2013},\n}\n\n\n')
|
||||||
|
|
||||||
def test_deleteId(self):
|
def test_deleteId(self):
|
||||||
self.bibtex_article['file'] = params.folder+'test.pdf'
|
self.bibtex_article['file'] = config.get("folder")+'test.pdf'
|
||||||
bibtexAppend(self.bibtex_article)
|
bibtexAppend(self.bibtex_article)
|
||||||
open(params.folder+'test.pdf', 'w').close()
|
open(config.get("folder")+'test.pdf', 'w').close()
|
||||||
deleteId(self.bibtex_article['id'])
|
deleteId(self.bibtex_article['id'])
|
||||||
with open(params.folder+'index.bib', 'r') as fh:
|
with open(config.get("folder")+'index.bib', 'r') as fh:
|
||||||
self.assertEquals(fh.read().strip(), "")
|
self.assertEquals(fh.read().strip(), "")
|
||||||
self.assertFalse(os.path.isfile(params.folder+'test.pdf'))
|
self.assertFalse(os.path.isfile(config.get("folder")+'test.pdf'))
|
||||||
|
|
||||||
def test_deleteFile(self):
|
def test_deleteFile(self):
|
||||||
self.bibtex_article['file'] = params.folder+'test.pdf'
|
self.bibtex_article['file'] = config.get("folder")+'test.pdf'
|
||||||
bibtexAppend(self.bibtex_article)
|
bibtexAppend(self.bibtex_article)
|
||||||
open(params.folder+'test.pdf', 'w').close()
|
open(config.get("folder")+'test.pdf', 'w').close()
|
||||||
deleteFile(self.bibtex_article['file'])
|
deleteFile(self.bibtex_article['file'])
|
||||||
with open(params.folder+'index.bib', 'r') as fh:
|
with open(config.get("folder")+'index.bib', 'r') as fh:
|
||||||
self.assertEquals(fh.read().strip(), "")
|
self.assertEquals(fh.read().strip(), "")
|
||||||
self.assertFalse(os.path.isfile(params.folder+'test.pdf'))
|
self.assertFalse(os.path.isfile(config.get("folder")+'test.pdf'))
|
||||||
|
|
||||||
def test_diffFilesIndex(self):
|
def test_diffFilesIndex(self):
|
||||||
# TODO
|
# TODO
|
||||||
@ -126,17 +127,17 @@ Lattice},
|
|||||||
self.assertEqual(got, self.bibtex_article)
|
self.assertEqual(got, self.bibtex_article)
|
||||||
|
|
||||||
def test_getBibtex_file(self):
|
def test_getBibtex_file(self):
|
||||||
self.bibtex_article['file'] = params.folder+'test.pdf'
|
self.bibtex_article['file'] = config.get("folder")+'test.pdf'
|
||||||
open(params.folder+'test.pdf', 'w').close()
|
open(config.get("folder")+'test.pdf', 'w').close()
|
||||||
bibtexAppend(self.bibtex_article)
|
bibtexAppend(self.bibtex_article)
|
||||||
got = getBibtex(self.bibtex_article['file'], file_id='file')
|
got = getBibtex(self.bibtex_article['file'], file_id='file')
|
||||||
self.assertEqual(got, self.bibtex_article)
|
self.assertEqual(got, self.bibtex_article)
|
||||||
|
|
||||||
def test_getBibtex_clean(self):
|
def test_getBibtex_clean(self):
|
||||||
params.ignore_fields = ['id', 'abstract']
|
config.set("ignore_fields", ['id', 'abstract'])
|
||||||
bibtexAppend(self.bibtex_article)
|
bibtexAppend(self.bibtex_article)
|
||||||
got = getBibtex(self.bibtex_article['id'], clean=True)
|
got = getBibtex(self.bibtex_article['id'], clean=True)
|
||||||
for i in params.ignore_fields:
|
for i in config.get("ignore_fields"):
|
||||||
self.assertNotIn(i, got)
|
self.assertNotIn(i, got)
|
||||||
|
|
||||||
def test_getEntries(self):
|
def test_getEntries(self):
|
||||||
@ -153,7 +154,7 @@ Lattice},
|
|||||||
return
|
return
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(params.folder)
|
shutil.rmtree(config.get("folder"))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user