mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
linter cleanup
This commit is contained in:
parent
16d6e0cbcc
commit
a8057ed1db
4
Makefile
4
Makefile
@ -1,7 +1,7 @@
|
|||||||
VERSION = $(shell grep -oE "[0-9]+\.[0-9]+\.[0-9]+" bin/autojump)
|
VERSION = $(shell grep -oE "[0-9]+\.[0-9]+\.[0-9]+" bin/autojump)
|
||||||
TAGNAME = release-v$(VERSION)
|
TAGNAME = release-v$(VERSION)
|
||||||
|
|
||||||
.PHONY: docs install uninstall tar
|
.PHONY: docs install uninstall lint tar
|
||||||
|
|
||||||
install:
|
install:
|
||||||
install.sh
|
install.sh
|
||||||
@ -14,7 +14,7 @@ docs:
|
|||||||
pandoc -s -w markdown docs/header.md docs/install.md docs/development.md docs/body.md -o README.md
|
pandoc -s -w markdown docs/header.md docs/install.md docs/development.md docs/body.md -o README.md
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
flake8 ./
|
@flake8 ./ --config=setup.cfg
|
||||||
|
|
||||||
release: docs
|
release: docs
|
||||||
# Check for tag existence
|
# Check for tag existence
|
||||||
|
28
bin/autojump
28
bin/autojump
@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Copyright © 2008-2012 Joel Schaerer
|
Copyright © 2008-2012 Joel Schaerer
|
||||||
Copyright © 2012-2013 William Ting
|
Copyright © 2012-2014 William Ting
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -15,8 +15,8 @@
|
|||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
@ -93,9 +93,12 @@ def set_defaults():
|
|||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
"""Evaluate arguments and run appropriate logic, returning an error code."""
|
"""
|
||||||
|
Evaluate arguments and run appropriate logic, returning an error code.
|
||||||
|
"""
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description='Automatically jump to directory passed as an argument.',
|
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(
|
parser.add_argument(
|
||||||
'directory', metavar='DIRECTORY', nargs='*', default='',
|
'directory', metavar='DIRECTORY', nargs='*', default='',
|
||||||
@ -131,8 +134,9 @@ def add_path(data, path, increment=10):
|
|||||||
"""
|
"""
|
||||||
Add a new path or increment an existing one.
|
Add a new path or increment an existing one.
|
||||||
|
|
||||||
os.path.realpath() is not used because users prefer to have short, symlinked
|
os.path.realpath() is not used because users prefer to have short,
|
||||||
paths with duplicate entries in the database than a single canonical path.
|
symlinked paths with duplicate entries in the database than a single
|
||||||
|
canonical path.
|
||||||
"""
|
"""
|
||||||
path = decode(path).rstrip(os.sep)
|
path = decode(path).rstrip(os.sep)
|
||||||
if path == os.path.expanduser('~'):
|
if path == os.path.expanduser('~'):
|
||||||
@ -182,7 +186,6 @@ def find_matches(entries, needles):
|
|||||||
exists,
|
exists,
|
||||||
chain(
|
chain(
|
||||||
match_consecutive(needles, data, ignore_case),
|
match_consecutive(needles, data, ignore_case),
|
||||||
match_quicksilver(needles, data, ignore_case),
|
|
||||||
match_fuzzy(needles, data, ignore_case),
|
match_fuzzy(needles, data, ignore_case),
|
||||||
match_anywhere(needles, data, ignore_case),
|
match_anywhere(needles, data, ignore_case),
|
||||||
# default return value so calling shell functions have an
|
# default return value so calling shell functions have an
|
||||||
@ -289,14 +292,11 @@ def match_fuzzy(needles, haystack, ignore_case=False):
|
|||||||
match_percent = lambda entry: SequenceMatcher(
|
match_percent = lambda entry: SequenceMatcher(
|
||||||
a=needle,
|
a=needle,
|
||||||
b=end_dir(entry.path)).ratio()
|
b=end_dir(entry.path)).ratio()
|
||||||
meets_threshold = lambda entry: match_percent(entry) >= FUZZY_MATCH_THRESHOLD
|
meets_threshold = lambda entry: match_percent(entry) >= \
|
||||||
|
FUZZY_MATCH_THRESHOLD
|
||||||
return ifilter(meets_threshold, haystack)
|
return ifilter(meets_threshold, haystack)
|
||||||
|
|
||||||
|
|
||||||
def match_quicksilver(needles, haystack, ignore_case=False):
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def purge_missing_paths(entries):
|
def purge_missing_paths(entries):
|
||||||
"""Remove non-existent paths from a list of entries."""
|
"""Remove non-existent paths from a list of entries."""
|
||||||
exists = lambda entry: os.path.exists(entry.path)
|
exists = lambda entry: os.path.exists(entry.path)
|
||||||
@ -348,6 +348,8 @@ def main(args):
|
|||||||
print_stats(load(config), config['data_path'])
|
print_stats(load(config), config['data_path'])
|
||||||
else:
|
else:
|
||||||
if not args.directory:
|
if not args.directory:
|
||||||
|
# default return value so calling shell functions have an
|
||||||
|
# argument to `cd` to
|
||||||
print(encode_local('.'))
|
print(encode_local('.'))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
16
bin/data.py
16
bin/data.py
@ -72,7 +72,9 @@ def load(config):
|
|||||||
'r', encoding='utf-8',
|
'r', encoding='utf-8',
|
||||||
errors='replace') as f:
|
errors='replace') as f:
|
||||||
return dict(
|
return dict(
|
||||||
imap(tupleize, ifilter(correct_length, imap(parse, f))))
|
imap(
|
||||||
|
tupleize,
|
||||||
|
ifilter(correct_length, imap(parse, f))))
|
||||||
except (IOError, EOFError):
|
except (IOError, EOFError):
|
||||||
return load_backup(config)
|
return load_backup(config)
|
||||||
|
|
||||||
@ -116,12 +118,17 @@ def save(config, data):
|
|||||||
# atomically save by writing to temporary file and moving to destination
|
# atomically save by writing to temporary file and moving to destination
|
||||||
try:
|
try:
|
||||||
# write to temp file
|
# write to temp file
|
||||||
with open(config['tmp_path'], 'w', encoding='utf-8', errors='replace') as f:
|
with open(
|
||||||
|
config['tmp_path'],
|
||||||
|
'w',
|
||||||
|
encoding='utf-8',
|
||||||
|
errors='replace') as f:
|
||||||
for path, weight in data.items():
|
for path, weight in data.items():
|
||||||
if is_python3():
|
if is_python3():
|
||||||
f.write(("%s\t%s\n" % (weight, path)))
|
f.write(("%s\t%s\n" % (weight, path)))
|
||||||
else:
|
else:
|
||||||
f.write((unicode("%s\t%s\n" % (weight, path)).encode('utf-8')))
|
f.write(unicode(
|
||||||
|
"%s\t%s\n" % (weight, path)).encode('utf-8'))
|
||||||
|
|
||||||
f.flush()
|
f.flush()
|
||||||
os.fsync(f)
|
os.fsync(f)
|
||||||
@ -131,7 +138,8 @@ def save(config, data):
|
|||||||
|
|
||||||
# create backup file if it doesn't exist or is older than BACKUP_THRESHOLD
|
# create backup file if it doesn't exist or is older than BACKUP_THRESHOLD
|
||||||
if not os.path.exists(config['backup_path']) or \
|
if not os.path.exists(config['backup_path']) or \
|
||||||
(time() - os.path.getmtime(config['backup_path']) > BACKUP_THRESHOLD):
|
(time() - os.path.getmtime(config['backup_path'])
|
||||||
|
> BACKUP_THRESHOLD):
|
||||||
move_file(config['data_path'], config['backup_path'])
|
move_file(config['data_path'], config['backup_path'])
|
||||||
|
|
||||||
# move temp_file -> autojump.txt
|
# move temp_file -> autojump.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user