fix #17
This commit is contained in:
parent
78437acb4a
commit
84fd5d7649
@ -37,7 +37,7 @@ def command(args):
|
||||
color.dye(pubsdir, color.filepath)))
|
||||
ui.exit()
|
||||
|
||||
ui.print_('Initializing pubs in {}.'.format(
|
||||
ui.print_('Initializing pubs in {}'.format(
|
||||
color.dye(pubsdir, color.filepath)))
|
||||
|
||||
config().pubsdir = pubsdir
|
||||
|
@ -2,7 +2,10 @@ import os
|
||||
import collections
|
||||
|
||||
from .p3 import configparser
|
||||
from .content import system_path
|
||||
from . import content
|
||||
|
||||
from .content import system_path, check_file
|
||||
|
||||
|
||||
# constant stuff (DFT = DEFAULT)
|
||||
|
||||
@ -61,11 +64,17 @@ class Config(object):
|
||||
_config = self
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
|
@ -11,7 +11,7 @@ from .p3 import urlparse, HTTPConnection, urlopen
|
||||
def _check_system_path_exists(path, fail=True):
|
||||
answer = os.path.exists(path)
|
||||
if not answer and fail:
|
||||
raise IOError("File does not exist: {}.".format(path))
|
||||
raise IOError("File does not exist: {}".format(path))
|
||||
else:
|
||||
return answer
|
||||
|
||||
|
@ -58,7 +58,12 @@ def _update_check(config, ui):
|
||||
def execute(raw_args=sys.argv):
|
||||
# loading config
|
||||
config = configs.Config()
|
||||
if raw_args[1] != 'init':
|
||||
try:
|
||||
config.load()
|
||||
except IOError as e:
|
||||
print('error: {}'.format(str(e)))
|
||||
sys.exit()
|
||||
config.as_global()
|
||||
|
||||
uis.init_ui(config)
|
||||
|
@ -5,7 +5,7 @@ import os
|
||||
import dotdot
|
||||
import fake_env
|
||||
|
||||
from pubs import content, filebroker, databroker, datacache
|
||||
from pubs import content, filebroker, databroker, datacache, configs
|
||||
|
||||
import str_fixtures
|
||||
from pubs import endecoder
|
||||
@ -20,7 +20,7 @@ class TestDataBroker(unittest.TestCase):
|
||||
page99_bibdata = ende.decode_bibdata(str_fixtures.bibtex_raw0)
|
||||
|
||||
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)
|
||||
|
||||
|
@ -7,14 +7,19 @@ import dotdot
|
||||
import fake_env
|
||||
|
||||
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 fixtures
|
||||
|
||||
|
||||
from pubs.commands import init_cmd, import_cmd
|
||||
|
||||
|
||||
# makes the tests very noisy
|
||||
PRINT_OUTPUT=False
|
||||
CAPTURE_OUTPUT=True
|
||||
|
||||
|
||||
# code for fake fs
|
||||
|
||||
class TestFakeInput(unittest.TestCase):
|
||||
@ -50,9 +55,9 @@ class CommandTestCase(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
assert(stderr.getvalue() == '')
|
||||
outs.append(color.undye(stdout.getvalue()))
|
||||
if PRINT_OUTPUT:
|
||||
print(outs)
|
||||
return outs
|
||||
|
||||
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):
|
||||
@ -206,7 +213,7 @@ class TestList(DataCommandTestCase):
|
||||
class TestUsecase(DataCommandTestCase):
|
||||
|
||||
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',
|
||||
'',
|
||||
|
Loading…
x
Reference in New Issue
Block a user