Ver a proveniência

Add a --cleanup flag to remove old bookmarks (closes #26).

tags/v0.4
Ben Kurtovic há 8 anos
ascendente
cometimento
a51b99d98a
3 ficheiros alterados com 28 adições e 4 eliminações
  1. +2
    -1
      CHANGELOG
  2. +19
    -2
      gitup/config.py
  3. +7
    -1
      gitup/script.py

+ 2
- 1
CHANGELOG Ver ficheiro

@@ -2,7 +2,8 @@ v0.3.1 (unreleased):

- Added a `--prune` flag to delete remote-tracking branches that no longer
exist on their remote after fetching.
- Added a '--bookmark-file' option to support multiple bookmark config files.
- Added a `--bookmark-file` flag to support multiple bookmark config files.
- Added a `--cleanup` flag to remove old bookmarks that don't exist.
- Cleaned up the bookmark file format, fixing a related Windows bug. The script
will automatically migrate to the new one.
- Fixed a bug related to Python 3 compatibility.


+ 19
- 2
gitup/config.py Ver ficheiro

@@ -12,7 +12,7 @@ from colorama import Fore, Style
from .migrate import run_migrations

__all__ = ["get_default_config_path", "get_bookmarks", "add_bookmarks",
"delete_bookmarks", "list_bookmarks"]
"delete_bookmarks", "list_bookmarks", "clean_bookmarks"]

YELLOW = Fore.YELLOW + Style.BRIGHT
RED = Fore.RED + Style.BRIGHT
@@ -106,10 +106,27 @@ def delete_bookmarks(paths, config_path=None):

def list_bookmarks(config_path=None):
"""Print all of our current bookmarks."""
bookmarks = get_bookmarks(config_path=config_path)
bookmarks = _load_config_file(config_path)
if bookmarks:
print(YELLOW + "Current bookmarks:")
for bookmark_path in bookmarks:
print(INDENT1, bookmark_path)
else:
print("You have no bookmarks to display.")

def clean_bookmarks(config_path=None):
"""Delete any bookmarks that don't exist."""
bookmarks = _load_config_file(config_path)
if not bookmarks:
return

delete = [path for path in bookmarks if not os.path.isdir(path)]
if not delete:
return

bookmarks = [path for path in bookmarks if path not in delete]
_save_config_file(bookmarks, config_path)

print(YELLOW + "Deleted bookmarks:")
for path in delete:
print(INDENT1, path)

+ 7
- 1
gitup/script.py Ver ficheiro

@@ -13,7 +13,7 @@ from colorama import init as color_init, Fore, Style

from . import __version__
from .config import (get_default_config_path, get_bookmarks, add_bookmarks,
delete_bookmarks, list_bookmarks)
delete_bookmarks, list_bookmarks, clean_bookmarks)
from .update import update_bookmarks, update_directories

def _decode(path):
@@ -64,6 +64,9 @@ def main():
'-l', '--list', dest="list_bookmarks", action="store_true",
help="list current bookmarks")
group_b.add_argument(
'-e', '--clean', '--cleanup', dest="clean_bookmarks",
action="store_true", help="delete any bookmarks that don't exist")
group_b.add_argument(
'-b', '--bookmark-file', nargs="?", metavar="path", type=_decode,
help="use a specific bookmark config file (default: {0})".format(
get_default_config_path()))
@@ -107,6 +110,9 @@ def main():
if args.list_bookmarks:
list_bookmarks(args.bookmark_file)
acted = True
if args.clean_bookmarks:
clean_bookmarks(args.bookmark_file)
acted = True
if args.directories_to_update:
update_directories(args.directories_to_update, update_args)
acted = True


Carregando…
Cancelar
Guardar