summary refs log tree commit diff stats
path: root/ranger.py
blob: 6915457f5a613e6125280cafa6373c89947dcf4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
# coding=utf-8
# ranger: Explore your forest of files from inside your terminal
#
# Copyright (c) 2009, 2010 hut <hut@lavabit.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ----------------------------------------------------------------------------
#
# An embedded shell script. It allows you to change the directory
# of the parent shell to the last visited directory in ranger after exit.
# For more information, check out doc/cd-after-exit.txt
# To enable this, start ranger with:
#     source /path/ranger /path/ranger
"""":
if [ $1 ]; then
	RANGER="$1"
	shift
	cd "`$RANGER --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`"
else
	echo "usage: source path/to/ranger.py path/to/ranger.py"
fi
return 1
"""

# Redefine the docstring, since the previous one was hijacked to
# embed a shellscript.
__doc__ = """Ranger - file browser for the unix terminal"""


# Importing the main method may fail if the ranger directory
# is neither in the same directory as this file, nor in one of
# pythons global import paths.
try:
	from ranger import main

except ImportError as errormessage:
	if str(errormessage).endswith("main"):
		print("Can't import the main module.")
		print("To run an uninstalled copy of ranger,")
		print("launch ranger.py in the top directory.")
	else:
		raise

else:
	main()
="w"> if !newtime.After(prevtime) || newtime == prevtime { t.Errorf("Cache time did not update, check refreshCache() logic\n") } }) } func Benchmark_refreshCache(b *testing.B) { initTestConf() b.ResetTimer() for i := 0; i < b.N; i++ { refreshCache() } } func Test_pushpullDatabase(t *testing.T) { initTestConf() initDatabase() out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt") if err != nil { t.Errorf("Couldn't set up test: %v\n", err) } statusmap, err := registry.ParseUserTwtxt(out, "gbmor", "https://gbmor.dev/twtxt.txt") if err != nil { t.Errorf("Couldn't set up test: %v\n", err) } twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap) t.Run("Push to Database", func(t *testing.T) { err := pushDatabase() if err != nil { t.Errorf("%v\n", err) } }) t.Run("Clearing Registry", func(t *testing.T) { err := twtxtCache.DelUser("https://gbmor.dev/twtxt.txt") if err != nil { t.Errorf("%v", err) } }) t.Run("Pulling from Database", func(t *testing.T) { pullDatabase() twtxtCache.Mu.RLock() if _, ok := twtxtCache.Users["https://gbmor.dev/twtxt.txt"]; !ok { t.Errorf("Missing user previously pushed to database\n") } twtxtCache.Mu.RUnlock() }) } func Benchmark_pushDatabase(b *testing.B) { initTestConf() if len(dbChan) < 1 { initDatabase() } if _, ok := twtxtCache.Users["https://gbmor.dev/twtxt.txt"]; !ok { out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt") if err != nil { b.Errorf("Couldn't set up benchmark: %v\n", err) } statusmap, err := registry.ParseUserTwtxt(out, "gbmor", "https://gbmor.dev/twtxt.txt") if err != nil { b.Errorf("Couldn't set up benchmark: %v\n", err) } twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap) } b.ResetTimer() for i := 0; i < b.N; i++ { err := pushDatabase() if err != nil { b.Errorf("%v\n", err) } } } func Benchmark_pullDatabase(b *testing.B) { initTestConf() if len(dbChan) < 1 { initDatabase() } for i := 0; i < b.N; i++ { pullDatabase() } }