summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-01-11 11:49:34 +0100
committerhut <hut@lavabit.com>2012-01-11 16:58:12 +0100
commit907e3fde740f69b4ef9bc8fa4a7090512583baf7 (patch)
tree56f8cc3dbeec17c20c3aeef45fc81979a2d59ad6
parent999a9268aa3d8104d864131d7ad4ee6d6b2a643b (diff)
downloadranger-907e3fde740f69b4ef9bc8fa4a7090512583baf7.tar.gz
added --profile option
-rw-r--r--ranger/core/helper.py5
-rw-r--r--ranger/core/main.py28
2 files changed, 32 insertions, 1 deletions
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index 88072e13..446d9328 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -68,6 +68,11 @@ def parse_arguments():
 			help="List common keys which are not bound to any action.")
 	parser.add_option('--selectfile', type='string', metavar='filepath',
 			help="Open ranger with supplied file selected.")
+	parser.add_option('--list-tagged-files', type='string', default=None,
+			metavar='tag',
+			help="List all files which are tagged with the given tag, default: *")
+	parser.add_option('--profile', action='store_true',
+			help="Print statistics of CPU usage on exit.")
 
 	options, positional = parser.parse_args()
 	arg = OpenStruct(options.__dict__, targets=positional)
diff --git a/ranger/core/main.py b/ranger/core/main.py
index b69e3c6d..1c2686bb 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -46,6 +46,20 @@ def main():
 		fm = FM()
 		fm.copy_config_files(arg.copy_config)
 		return 1 if arg.fail_unless_cd else 0
+	if arg.list_tagged_files:
+		fm = FM()
+		try:
+			f = open(fm.confpath('tagged'), 'r')
+		except:
+			pass
+		else:
+			for line in f.readlines():
+				if len(line) > 2 and line[1] == ':':
+					if line[0] in arg.list_tagged_files:
+						sys.stdout.write(line[2:])
+				elif len(line) > 0 and '*' in arg.list_tagged_files:
+					sys.stdout.write(line)
+		return 1 if arg.fail_unless_cd else 0
 
 	SettingsAware._setup(clean=arg.clean)
 
@@ -107,7 +121,15 @@ def main():
 		# Run the file manager
 		fm.initialize()
 		fm.ui.initialize()
-		fm.loop()
+		if ranger.arg.profile:
+			import cProfile
+			import pstats
+			profile = None
+			ranger.__fm = fm
+			cProfile.run('ranger.__fm.loop()', '/tmp/ranger_profile')
+			profile = pstats.Stats('/tmp/ranger_profile')
+		else:
+			fm.loop()
 	except Exception:
 		import traceback
 		crash_traceback = traceback.format_exc()
@@ -123,6 +145,10 @@ def main():
 			fm.ui.destroy()
 		except (AttributeError, NameError):
 			pass
+		if ranger.arg.profile and profile:
+			stdout, sys.stdout = sys.stdout, sys.stderr
+			profile.strip_dirs().sort_stats('cumulative').print_callees(100)
+			sys.stdout = stdout
 		if crash_traceback:
 			print("ranger version: %s, executed with python %s" %
 					(ranger.__version__, sys.version.split()[0]))