fix #17
This commit is contained in:
parent
78437acb4a
commit
84fd5d7649
@ -37,7 +37,7 @@ def command(args):
|
|||||||
color.dye(pubsdir, color.filepath)))
|
color.dye(pubsdir, color.filepath)))
|
||||||
ui.exit()
|
ui.exit()
|
||||||
|
|
||||||
ui.print_('Initializing pubs in {}.'.format(
|
ui.print_('Initializing pubs in {}'.format(
|
||||||
color.dye(pubsdir, color.filepath)))
|
color.dye(pubsdir, color.filepath)))
|
||||||
|
|
||||||
config().pubsdir = pubsdir
|
config().pubsdir = pubsdir
|
||||||
|
@ -2,7 +2,10 @@ import os
|
|||||||
import collections
|
import collections
|
||||||
|
|
||||||
from .p3 import configparser
|
from .p3 import configparser
|
||||||
from .content import system_path
|
from . import content
|
||||||
|
|
||||||
|
from .content import system_path, check_file
|
||||||
|
|
||||||
|
|
||||||
# constant stuff (DFT = DEFAULT)
|
# constant stuff (DFT = DEFAULT)
|
||||||
|
|
||||||
@ -61,11 +64,17 @@ class Config(object):
|
|||||||
_config = self
|
_config = self
|
||||||
|
|
||||||
def load(self, path=DFT_CONFIG_PATH):
|
def load(self, path=DFT_CONFIG_PATH):
|
||||||
self._cfg.read(path)
|
if not content.check_file(path, fail=False):
|
||||||
|
raise IOError(("The configuration file {} does not exist."
|
||||||
|
" Did you run 'pubs init' ?").format(path))
|
||||||
|
with open(content.system_path(path), 'r') as f:
|
||||||
|
read = self._cfg.readfp(f)
|
||||||
|
# if len(read) == 0:
|
||||||
|
# raise IOError("Syntax error in {} config file. Aborting.".format(path))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def save(self, path=DFT_CONFIG_PATH):
|
def save(self, path=DFT_CONFIG_PATH):
|
||||||
with open(system_path(path), 'w') as f:
|
with open(content.system_path(path), 'w') as f:
|
||||||
self._cfg.write(f)
|
self._cfg.write(f)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
|
@ -11,7 +11,7 @@ from .p3 import urlparse, HTTPConnection, urlopen
|
|||||||
def _check_system_path_exists(path, fail=True):
|
def _check_system_path_exists(path, fail=True):
|
||||||
answer = os.path.exists(path)
|
answer = os.path.exists(path)
|
||||||
if not answer and fail:
|
if not answer and fail:
|
||||||
raise IOError("File does not exist: {}.".format(path))
|
raise IOError("File does not exist: {}".format(path))
|
||||||
else:
|
else:
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
@ -58,7 +58,12 @@ def _update_check(config, ui):
|
|||||||
def execute(raw_args=sys.argv):
|
def execute(raw_args=sys.argv):
|
||||||
# loading config
|
# loading config
|
||||||
config = configs.Config()
|
config = configs.Config()
|
||||||
config.load()
|
if raw_args[1] != 'init':
|
||||||
|
try:
|
||||||
|
config.load()
|
||||||
|
except IOError as e:
|
||||||
|
print('error: {}'.format(str(e)))
|
||||||
|
sys.exit()
|
||||||
config.as_global()
|
config.as_global()
|
||||||
|
|
||||||
uis.init_ui(config)
|
uis.init_ui(config)
|
||||||
|
@ -5,7 +5,7 @@ import os
|
|||||||
import dotdot
|
import dotdot
|
||||||
import fake_env
|
import fake_env
|
||||||
|
|
||||||
from pubs import content, filebroker, databroker, datacache
|
from pubs import content, filebroker, databroker, datacache, configs
|
||||||
|
|
||||||
import str_fixtures
|
import str_fixtures
|
||||||
from pubs import endecoder
|
from pubs import endecoder
|
||||||
@ -20,7 +20,7 @@ class TestDataBroker(unittest.TestCase):
|
|||||||
page99_bibdata = ende.decode_bibdata(str_fixtures.bibtex_raw0)
|
page99_bibdata = ende.decode_bibdata(str_fixtures.bibtex_raw0)
|
||||||
|
|
||||||
for db_class in [databroker.DataBroker, datacache.DataCache]:
|
for db_class in [databroker.DataBroker, datacache.DataCache]:
|
||||||
self.fs = fake_env.create_fake_fs([content, filebroker])
|
self.fs = fake_env.create_fake_fs([content, filebroker, configs])
|
||||||
|
|
||||||
db = db_class('tmp', create=True)
|
db = db_class('tmp', create=True)
|
||||||
|
|
||||||
|
@ -7,14 +7,19 @@ import dotdot
|
|||||||
import fake_env
|
import fake_env
|
||||||
|
|
||||||
from pubs import pubs_cmd
|
from pubs import pubs_cmd
|
||||||
from pubs import color, content, filebroker, uis, beets_ui, p3, endecoder
|
from pubs import color, content, filebroker, uis, beets_ui, p3, endecoder, configs
|
||||||
|
|
||||||
import str_fixtures
|
import str_fixtures
|
||||||
import fixtures
|
import fixtures
|
||||||
|
|
||||||
|
|
||||||
from pubs.commands import init_cmd, import_cmd
|
from pubs.commands import init_cmd, import_cmd
|
||||||
|
|
||||||
|
|
||||||
|
# makes the tests very noisy
|
||||||
|
PRINT_OUTPUT=False
|
||||||
|
CAPTURE_OUTPUT=True
|
||||||
|
|
||||||
|
|
||||||
# code for fake fs
|
# code for fake fs
|
||||||
|
|
||||||
class TestFakeInput(unittest.TestCase):
|
class TestFakeInput(unittest.TestCase):
|
||||||
@ -50,9 +55,9 @@ class CommandTestCase(unittest.TestCase):
|
|||||||
maxDiff = None
|
maxDiff = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.fs = fake_env.create_fake_fs([content, filebroker, init_cmd, import_cmd])
|
self.fs = fake_env.create_fake_fs([content, filebroker, configs, init_cmd, import_cmd])
|
||||||
|
|
||||||
def execute_cmds(self, cmds, fs=None, capture_output=True):
|
def execute_cmds(self, cmds, fs=None, capture_output=CAPTURE_OUTPUT):
|
||||||
""" Execute a list of commands, and capture their output
|
""" Execute a list of commands, and capture their output
|
||||||
|
|
||||||
A command can be a string, or a tuple of size 2 or 3.
|
A command can be a string, or a tuple of size 2 or 3.
|
||||||
@ -88,10 +93,12 @@ class CommandTestCase(unittest.TestCase):
|
|||||||
if capture_output:
|
if capture_output:
|
||||||
assert(stderr.getvalue() == '')
|
assert(stderr.getvalue() == '')
|
||||||
outs.append(color.undye(stdout.getvalue()))
|
outs.append(color.undye(stdout.getvalue()))
|
||||||
|
if PRINT_OUTPUT:
|
||||||
|
print(outs)
|
||||||
return outs
|
return outs
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
fake_env.unset_fake_fs([content, filebroker])
|
fake_env.unset_fake_fs([content, filebroker, configs, init_cmd, import_cmd])
|
||||||
|
|
||||||
|
|
||||||
class DataCommandTestCase(CommandTestCase):
|
class DataCommandTestCase(CommandTestCase):
|
||||||
@ -206,7 +213,7 @@ class TestList(DataCommandTestCase):
|
|||||||
class TestUsecase(DataCommandTestCase):
|
class TestUsecase(DataCommandTestCase):
|
||||||
|
|
||||||
def test_first(self):
|
def test_first(self):
|
||||||
correct = ['Initializing pubs in /paper_first.\n',
|
correct = ['Initializing pubs in /paper_first\n',
|
||||||
'',
|
'',
|
||||||
'[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n',
|
'[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n',
|
||||||
'',
|
'',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user