Jason R. Coombs avatar Jason R. Coombs committed 399d101

Added command to mark .hg directories as hidden

Comments (0)

Files changed (2)

jaraco/develop/mercurial.py

 import re
 import logging
 import itertools
+import importlib
 
 import path
 import jaraco.util.logging
 log = logging.getLogger(__name__)
 
 def get_hgrcs(base, recurse=False):
+	hg_dirs = get_hg_dirs(base, recurse)
+	return (dir / 'hgrc' for dir in hg_dirs if (dir / 'hgrc').isfile())
+
+def get_hg_dirs(base, recurse=False):
 	candidates = (base,)
 	if recurse:
 		candidates = itertools.chain(candidates, base.walkdirs())
 	candidates = (dir for dir in candidates if dir.basename() != '.hg')
-	hgrcs = (dir / '.hg' / 'hgrc' for dir in candidates)
-	return (hgrc for hgrc in hgrcs if hgrc.isfile())
+	hg_dirs = (dir / '.hg' for dir in candidates if (dir / '.hg').isdir())
+	return hg_dirs
 
 def replace(filename, pattern, repl):
 	with open(filename, 'rb') as file:
 	for hgrc in get_hgrcs(path.path('.'), recurse=args.recurse):
 		if args.replace:
 			replace(hgrc, *args.replace)
+
+def hide_hg_dirs():
+	"""
+	Only useful on Windows, mark the .hg directory as hidden.
+	"""
+	fs = importlib.import_module('jaraco.windows.filesystem')
+	parser = argparse.ArgumentParser()
+	parser.add_argument('-r', '--recurse', default=False, action="store_true")
+	jaraco.util.logging.add_arguments(parser)
+	args = parser.parse_args()
+	jaraco.util.logging.setup(args, format="%(levelname)s:%(message)s")
+	for hg_dir in get_hg_dirs(path.path('.'), recurse=args.recurse):
+		# make the file hidden
+		fs.SetFileAttributes(hg_dir, 'hidden')
 			'vs-upgrade = jaraco.develop.vstudio:upgrade_file',
 			'set-tabs-mode = jaraco.develop.indent:set_tabs_mode_cmd',
 			'patch-hgrc = jaraco.develop.mercurial:patch_hgrc',
+			'hide-hg-dirs = jaraco.develop.mercurial:hide_hg_dirs',
 		],
 	},
 	install_requires=[
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.