mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
minor refactor
This commit is contained in:
parent
1d317dcd1a
commit
4bd62e2293
@ -359,6 +359,7 @@ def print_stats(data, data_path):
|
|||||||
|
|
||||||
def main(args): # noqa
|
def main(args): # noqa
|
||||||
config = set_defaults()
|
config = set_defaults()
|
||||||
|
|
||||||
# all arguments are mutually exclusive
|
# all arguments are mutually exclusive
|
||||||
if args.add:
|
if args.add:
|
||||||
save(config, first(add_path(load(config), args.add)))
|
save(config, first(add_path(load(config), args.add)))
|
||||||
@ -404,7 +405,7 @@ def main(args): # noqa
|
|||||||
first(
|
first(
|
||||||
chain(
|
chain(
|
||||||
find_matches(entries, needles),
|
find_matches(entries, needles),
|
||||||
# always return an argument to calling shell functions
|
# always return n argument to calling shell functions
|
||||||
[Entry('.', 0)])).path)
|
[Entry('.', 0)])).path)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -58,28 +58,28 @@ def load(config):
|
|||||||
if is_osx() and os.path.exists(xdg_aj_home):
|
if is_osx() and os.path.exists(xdg_aj_home):
|
||||||
migrate_osx_xdg_data(config)
|
migrate_osx_xdg_data(config)
|
||||||
|
|
||||||
if os.path.exists(config['data_path']):
|
if not os.path.exists(config['data_path']):
|
||||||
# example: u'10.0\t/home/user\n' -> ['10.0', u'/home/user']
|
return {}
|
||||||
parse = lambda line: line.strip().split('\t')
|
|
||||||
|
|
||||||
correct_length = lambda x: len(x) == 2
|
# example: u'10.0\t/home/user\n' -> ['10.0', u'/home/user']
|
||||||
|
parse = lambda line: line.strip().split('\t')
|
||||||
|
|
||||||
# example: ['10.0', u'/home/user'] -> (u'/home/user', 10.0)
|
correct_length = lambda x: len(x) == 2
|
||||||
tupleize = lambda x: (x[1], float(x[0]))
|
|
||||||
|
|
||||||
try:
|
# example: ['10.0', u'/home/user'] -> (u'/home/user', 10.0)
|
||||||
with open(
|
tupleize = lambda x: (x[1], float(x[0]))
|
||||||
config['data_path'],
|
|
||||||
'r', encoding='utf-8',
|
|
||||||
errors='replace') as f:
|
|
||||||
return dict(
|
|
||||||
imap(
|
|
||||||
tupleize,
|
|
||||||
ifilter(correct_length, imap(parse, f))))
|
|
||||||
except (IOError, EOFError):
|
|
||||||
return load_backup(config)
|
|
||||||
|
|
||||||
return {}
|
try:
|
||||||
|
with open(
|
||||||
|
config['data_path'],
|
||||||
|
'r', encoding='utf-8',
|
||||||
|
errors='replace') as f:
|
||||||
|
return dict(
|
||||||
|
imap(
|
||||||
|
tupleize,
|
||||||
|
ifilter(correct_length, imap(parse, f))))
|
||||||
|
except (IOError, EOFError):
|
||||||
|
return load_backup(config)
|
||||||
|
|
||||||
|
|
||||||
def load_backup(config):
|
def load_backup(config):
|
||||||
|
Loading…
Reference in New Issue
Block a user