move config back to global space

pull/125/head
William Ting 12 years ago
parent 7123e23706
commit e62e720765

@ -30,4 +30,4 @@ release:
git archive --format=tar --prefix autojump_$(VERSION)/ $(TAGNAME) | gzip > autojump_$(VERSION).tar.gz git archive --format=tar --prefix autojump_$(VERSION)/ $(TAGNAME) | gzip > autojump_$(VERSION).tar.gz
test: test:
python tests/runtests.py @tests/runtests.py

@ -29,7 +29,7 @@ import shutil
import sys import sys
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
VERSION = 'release-v20-6' VERSION = 'release-v20-7'
MAX_KEYWEIGHT = 1000 MAX_KEYWEIGHT = 1000
MAX_STORED_PATHS = 1000 MAX_STORED_PATHS = 1000
COMPLETION_SEPARATOR = '__' COMPLETION_SEPARATOR = '__'
@ -37,32 +37,27 @@ ARGS = None
CONFIG_DIR = None CONFIG_DIR = None
DB_FILE = None DB_FILE = None
TESTING = False TESTING = False
KEEP_ALL_ENTRIES = False
IGNORE_CASE = False
def config(testing=False): # load config from environmental variables
global TESTING, CONFIG_DIR, KEEP_ALL_ENTRIES, DB_FILE if 'AUTOJUMP_DATA_DIR' in os.environ:
TESTING = testing CONFIG_DIR = os.environ.get('AUTOJUMP_DATA_DIR')
else:
# load config from environmental variables xdg_data_dir = os.environ.get('XDG_DATA_HOME') or os.path.join(os.environ['HOME'], '.local', 'share')
if 'AUTOJUMP_DATA_DIR' in os.environ: CONFIG_DIR = os.path.join(xdg_data_dir, 'autojump')
CONFIG_DIR = os.environ.get('AUTOJUMP_DATA_DIR')
else:
xdg_data_dir = os.environ.get('XDG_DATA_HOME') or os.path.join(os.environ['HOME'], '.local', 'share')
CONFIG_DIR = os.path.join(xdg_data_dir, 'autojump')
if 'AUTOJUMP_KEEP_ALL_ENTRIES' in os.environ and os.environ.get('AUTOJUMP_KEEP_ALL_ENTRIES') == '1': KEEP_ALL_ENTRIES = False
KEEP_ALL_ENTRIES = True if 'AUTOJUMP_KEEP_ALL_ENTRIES' in os.environ and os.environ.get('AUTOJUMP_KEEP_ALL_ENTRIES') == '1':
KEEP_ALL_ENTRIES = True
if 'AUTOJUMP_IGNORE_CASE' in os.environ and os.environ.get('AUTOJUMP_IGNORE_CASE') == '1': ALWAYS_IGNORE_CASE = False
ALWAYS_IGNORE_CASE = True if 'AUTOJUMP_IGNORE_CASE' in os.environ and os.environ.get('AUTOJUMP_IGNORE_CASE') == '1':
ALWAYS_IGNORE_CASE = True
if CONFIG_DIR == os.path.expanduser('~'): if CONFIG_DIR == os.path.expanduser('~'):
DB_FILE = CONFIG_DIR + '/.autojump.txt' DB_FILE = CONFIG_DIR + '/.autojump.txt'
else: else:
DB_FILE = CONFIG_DIR + '/autojump.txt' DB_FILE = CONFIG_DIR + '/autojump.txt'
class Database: class Database:
""" """
@ -226,6 +221,8 @@ def options():
""" """
Parse command line options. Parse command line options.
""" """
global ARGS
parser = argparse.ArgumentParser(description='Automatically jump to directory passed as an argument.', parser = argparse.ArgumentParser(description='Automatically jump to directory passed as an argument.',
epilog="Please see autojump(1) man pages for full documentation.") epilog="Please see autojump(1) man pages for full documentation.")
parser.add_argument('directory', metavar='DIR', nargs='*', default='', parser.add_argument('directory', metavar='DIR', nargs='*', default='',
@ -403,10 +400,6 @@ def shell_utility():
Run this when autojump is called as a shell utility. Run this when autojump is called as a shell utility.
""" """
if options(): return True if options(): return True
config()
global ARGS, COMPLETION_SEPARATOR, DB_FILE, \
ALWAYS_IGNORE_CASE, KEEP_ALL_ENTRIES
db = Database(DB_FILE) db = Database(DB_FILE)
# if no directories, add empty string # if no directories, add empty string

@ -13,7 +13,7 @@ import unittest
class TestAutojump(unittest.TestCase): class TestAutojump(unittest.TestCase):
def setUp(self): def setUp(self):
autojump.config(True) autojump.TESTING = True
self.fd, DB_FILE = tempfile.mkstemp() self.fd, DB_FILE = tempfile.mkstemp()
self.db = autojump.Database(DB_FILE) self.db = autojump.Database(DB_FILE)
pass pass

Loading…
Cancel
Save