Custom masks support
This commit is contained in:
parent
90104f7019
commit
36a19fbab4
@ -15,10 +15,13 @@ import re
|
|||||||
import tools
|
import tools
|
||||||
import fetcher
|
import fetcher
|
||||||
from bibtexparser.bparser import BibTexParser
|
from bibtexparser.bparser import BibTexParser
|
||||||
from config import config
|
from config import Config
|
||||||
from codecs import open
|
from codecs import open
|
||||||
|
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
|
||||||
|
|
||||||
def getNewName(src, bibtex, tag='', override_format=None):
|
def getNewName(src, bibtex, tag='', override_format=None):
|
||||||
"""
|
"""
|
||||||
Return the formatted name according to config for the given
|
Return the formatted name according to config for the given
|
||||||
@ -88,7 +91,8 @@ def bibtexAppend(data):
|
|||||||
with open(config.get("folder")+'index.bib', 'a', encoding='utf-8') \
|
with open(config.get("folder")+'index.bib', 'a', encoding='utf-8') \
|
||||||
as fh:
|
as fh:
|
||||||
fh.write(tools.parsed2Bibtex(data)+"\n")
|
fh.write(tools.parsed2Bibtex(data)+"\n")
|
||||||
except:
|
except Exception as e:
|
||||||
|
raise e
|
||||||
tools.warning("Unable to open index file.")
|
tools.warning("Unable to open index file.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
4
bmc.py
4
bmc.py
@ -13,8 +13,10 @@ import tearpages
|
|||||||
import tools
|
import tools
|
||||||
from bibtexparser.bparser import BibTexParser
|
from bibtexparser.bparser import BibTexParser
|
||||||
from codecs import open
|
from codecs import open
|
||||||
from config import config
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
|
config = 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'
|
||||||
|
|
||||||
|
|
||||||
|
28
config.py
28
config.py
@ -1,5 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import errno
|
import errno
|
||||||
|
import imp
|
||||||
|
import inspect
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import tools
|
import tools
|
||||||
@ -34,11 +36,15 @@ def make_sure_path_exists(path):
|
|||||||
|
|
||||||
|
|
||||||
class Config():
|
class Config():
|
||||||
def __init__(self):
|
def __init__(self, base_config_path="~/.config/bmc/"):
|
||||||
self.config_path = os.path.expanduser("~/.config/")
|
self.config_path = os.path.expanduser(base_config_path)
|
||||||
self.config = {}
|
self.config = {}
|
||||||
|
self.config["format_custom"] = []
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
|
def as_dict(self):
|
||||||
|
return self.config
|
||||||
|
|
||||||
def get(self, param):
|
def get(self, param):
|
||||||
return self.config.get(param, False)
|
return self.config.get(param, False)
|
||||||
|
|
||||||
@ -73,6 +79,7 @@ class Config():
|
|||||||
except (ValueError, IOError):
|
except (ValueError, IOError):
|
||||||
tools.warning("Config file could not be read.")
|
tools.warning("Config file could not be read.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
self.load_masks()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
try:
|
try:
|
||||||
@ -82,4 +89,19 @@ class Config():
|
|||||||
tools.warning("Could not write config file.")
|
tools.warning("Could not write config file.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
config = Config()
|
def load_masks(self):
|
||||||
|
if os.path.isfile(self.config_path + "masks.py"):
|
||||||
|
try:
|
||||||
|
self.info = imp.find_module("masks", [self.config_path])
|
||||||
|
self.masks = imp.load_module("masks", *self.info)
|
||||||
|
for mask in inspect.getmembers(self.masks, inspect.isfunction):
|
||||||
|
self.config["format_custom"].append(mask[1])
|
||||||
|
except ImportError:
|
||||||
|
self.clean()
|
||||||
|
tools.warning("Unable to import masks config file.")
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
self.info[0].close()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
@ -18,10 +18,13 @@ import sys
|
|||||||
import arxiv2bib as arxiv_metadata
|
import arxiv2bib as arxiv_metadata
|
||||||
import tools
|
import tools
|
||||||
from bibtexparser.bparser import BibTexParser
|
from bibtexparser.bparser import BibTexParser
|
||||||
from config import config
|
from config import Config
|
||||||
from isbntools.dev._fmt import fmtbib
|
from isbntools.dev._fmt import fmtbib
|
||||||
|
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
|
||||||
|
|
||||||
def download(url):
|
def download(url):
|
||||||
"""Download url tofile
|
"""Download url tofile
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
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
|
||||||
@ -34,7 +33,7 @@ mass density wave should occur.},
|
|||||||
archiveprefix={arXiv},
|
archiveprefix={arXiv},
|
||||||
author={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},
|
author={N. Bartolo and D. J. Papoular and L. Barbiero and C. Menotti and A. Recati},
|
||||||
eprint={1303.3130v1},
|
eprint={1303.3130v1},
|
||||||
file={/home/phyks/Papers/N_Bartolo_A_Recati-j-2013.pdf},
|
file={%sN_Bartolo_A_Recati-j-2013.pdf},
|
||||||
link={http://arxiv.org/abs/1303.3130v1},
|
link={http://arxiv.org/abs/1303.3130v1},
|
||||||
month={Mar},
|
month={Mar},
|
||||||
primaryclass={cond-mat.quant-gas},
|
primaryclass={cond-mat.quant-gas},
|
||||||
@ -42,7 +41,7 @@ mass density wave should occur.},
|
|||||||
title={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical
|
title={Dipolar-Induced Resonance for Ultracold Bosons in a Quasi-1D Optical
|
||||||
Lattice},
|
Lattice},
|
||||||
year={2013},
|
year={2013},
|
||||||
}"""
|
}""" % config.get("folder")
|
||||||
self.bibtex_article = BibTexParser(self.bibtex_article_string).get_entry_dict()
|
self.bibtex_article = BibTexParser(self.bibtex_article_string).get_entry_dict()
|
||||||
self.bibtex_article = self.bibtex_article[self.bibtex_article.keys()[0]]
|
self.bibtex_article = self.bibtex_article[self.bibtex_article.keys()[0]]
|
||||||
|
|
||||||
@ -78,21 +77,21 @@ Lattice},
|
|||||||
bibtexAppend(self.bibtex_article)
|
bibtexAppend(self.bibtex_article)
|
||||||
with open(config.get("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={'+config.get("folder")+'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(config.get("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={'+config.get("folder")+'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(config.get("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={%sN_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' % config.get("folder"))
|
||||||
|
|
||||||
def test_deleteId(self):
|
def test_deleteId(self):
|
||||||
self.bibtex_article['file'] = config.get("folder")+'test.pdf'
|
self.bibtex_article['file'] = config.get("folder")+'test.pdf'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user