tor-commits
Threads by month
- ----- 2025 -----
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
September 2014
- 22 participants
- 980 discussions
commit 98e8d6993909089fd57bdcab01f9851b7cafa3f1
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 20:41:47 2014 -0700
Using stem's new util function names
Accounting for the newely renamed stem util functions.
---
arm/config_panel.py | 4 ++--
arm/connections/conn_entry.py | 2 +-
arm/controller.py | 2 +-
arm/graphing/bandwidth_stats.py | 26 +++++++++++++-------------
arm/graphing/graph_panel.py | 2 +-
arm/graphing/resource_stats.py | 4 ++--
arm/header_panel.py | 6 +++---
arm/starter.py | 2 +-
arm/util/tor_config.py | 6 +++---
arm/util/tracker.py | 4 ++--
run_tests.py | 4 ++--
11 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/arm/config_panel.py b/arm/config_panel.py
index e71948b..c2dac4b 100644
--- a/arm/config_panel.py
+++ b/arm/config_panel.py
@@ -205,9 +205,9 @@ class ConfigEntry():
elif self.get(Field.TYPE) == "Boolean" and conf_value in ("0", "1"):
conf_value = "False" if conf_value == "0" else "True"
elif self.get(Field.TYPE) == "DataSize" and conf_value.isdigit():
- conf_value = str_tools.get_size_label(int(conf_value))
+ conf_value = str_tools.size_label(int(conf_value))
elif self.get(Field.TYPE) == "TimeInterval" and conf_value.isdigit():
- conf_value = str_tools.get_time_label(int(conf_value), is_long = True)
+ conf_value = str_tools.time_label(int(conf_value), is_long = True)
return conf_value
diff --git a/arm/connections/conn_entry.py b/arm/connections/conn_entry.py
index 4b9a017..f3ea97a 100644
--- a/arm/connections/conn_entry.py
+++ b/arm/connections/conn_entry.py
@@ -351,7 +351,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
else:
time_prefix = ""
- time_label = time_prefix + "%5s" % str_tools.get_time_label(current_time - self.start_time, 1)
+ time_label = time_prefix + "%5s" % str_tools.time_label(current_time - self.start_time, 1)
my_listing[2] = (time_label, my_listing[2][1])
return my_listing
diff --git a/arm/controller.py b/arm/controller.py
index f18af9c..4a864b9 100644
--- a/arm/controller.py
+++ b/arm/controller.py
@@ -145,7 +145,7 @@ def init_controller(stdscr, start_time):
if tor_pid:
# use the tor pid to help narrow connection results
- tor_cmd = system.get_name_by_pid(tor_pid)
+ tor_cmd = system.name_by_pid(tor_pid)
if tor_cmd is None:
tor_cmd = "tor"
diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py
index 16cc349..dedde65 100644
--- a/arm/graphing/bandwidth_stats.py
+++ b/arm/graphing/bandwidth_stats.py
@@ -276,7 +276,7 @@ class BandwidthStats(graph_panel.GraphStats):
missing_sec = time.time() - min(last_read_time, last_write_time)
if missing_sec:
- msg += " (%s is missing)" % str_tools.get_time_label(missing_sec, 0, True)
+ msg += " (%s is missing)" % str_tools.time_label(missing_sec, 0, True)
log.notice(msg)
@@ -376,7 +376,7 @@ class BandwidthStats(graph_panel.GraphStats):
stats[1] = "- %s" % self._get_avg_label(is_primary)
stats[2] = ", %s" % self._get_total_label(is_primary)
- stats[0] = "%-14s" % ("%s/sec" % str_tools.get_size_label((self.last_primary if is_primary else self.last_secondary) * 1024, 1, False, CONFIG["features.graph.bw.transferInBytes"]))
+ stats[0] = "%-14s" % ("%s/sec" % str_tools.size_label((self.last_primary if is_primary else self.last_secondary) * 1024, 1, False, CONFIG["features.graph.bw.transferInBytes"]))
# drops label's components if there's not enough space
@@ -418,8 +418,8 @@ class BandwidthStats(graph_panel.GraphStats):
label_in_bytes = CONFIG["features.graph.bw.transferInBytes"]
if bw_rate and bw_burst:
- bw_rate_label = str_tools.get_size_label(bw_rate, 1, False, label_in_bytes)
- bw_burst_label = str_tools.get_size_label(bw_burst, 1, False, label_in_bytes)
+ bw_rate_label = str_tools.size_label(bw_rate, 1, False, label_in_bytes)
+ bw_burst_label = str_tools.size_label(bw_burst, 1, False, label_in_bytes)
# if both are using rounded values then strip off the ".0" decimal
@@ -435,9 +435,9 @@ class BandwidthStats(graph_panel.GraphStats):
# if there isn't yet enough bandwidth measurements).
if bw_observed and (not bw_measured or bw_measured == bw_observed):
- stats.append("observed: %s/s" % str_tools.get_size_label(bw_observed, 1, False, label_in_bytes))
+ stats.append("observed: %s/s" % str_tools.size_label(bw_observed, 1, False, label_in_bytes))
elif bw_measured:
- stats.append("measured: %s/s" % str_tools.get_size_label(bw_measured, 1, False, label_in_bytes))
+ stats.append("measured: %s/s" % str_tools.size_label(bw_measured, 1, False, label_in_bytes))
self._title_stats = stats
@@ -445,12 +445,12 @@ class BandwidthStats(graph_panel.GraphStats):
total = self.primary_total if is_primary else self.secondary_total
total += self.prepopulate_primary_total if is_primary else self.prepopulate_secondary_total
- return "avg: %s/sec" % str_tools.get_size_label((total / max(1, self.tick + self.prepopulate_ticks)) * 1024, 1, False, CONFIG["features.graph.bw.transferInBytes"])
+ return "avg: %s/sec" % str_tools.size_label((total / max(1, self.tick + self.prepopulate_ticks)) * 1024, 1, False, CONFIG["features.graph.bw.transferInBytes"])
def _get_total_label(self, is_primary):
total = self.primary_total if is_primary else self.secondary_total
total += self.initial_primary_total if is_primary else self.initial_secondary_total
- return "total: %s" % str_tools.get_size_label(total * 1024, 1)
+ return "total: %s" % str_tools.size_label(total * 1024, 1)
def _update_accounting_info(self):
"""
@@ -479,7 +479,7 @@ class BandwidthStats(graph_panel.GraphStats):
sec = time.mktime(time.strptime(end_interval, "%Y-%m-%d %H:%M:%S")) - time.time() - tz_offset
if CONFIG["features.graph.bw.accounting.isTimeLong"]:
- queried["reset_time"] = ", ".join(str_tools.get_time_labels(sec, True))
+ queried["reset_time"] = ", ".join(str_tools.time_labels(sec, True))
else:
days = sec / 86400
sec %= 86400
@@ -499,10 +499,10 @@ class BandwidthStats(graph_panel.GraphStats):
read, written = int(used_comp[0]), int(used_comp[1])
read_left, written_left = int(left_comp[0]), int(left_comp[1])
- queried["read"] = str_tools.get_size_label(read)
- queried["written"] = str_tools.get_size_label(written)
- queried["read_limit"] = str_tools.get_size_label(read + read_left)
- queried["writtenLimit"] = str_tools.get_size_label(written + written_left)
+ queried["read"] = str_tools.size_label(read)
+ queried["written"] = str_tools.size_label(written)
+ queried["read_limit"] = str_tools.size_label(read + read_left)
+ queried["writtenLimit"] = str_tools.size_label(written + written_left)
self.accounting_info = queried
self.accounting_last_updated = time.time()
diff --git a/arm/graphing/graph_panel.py b/arm/graphing/graph_panel.py
index b54b8b8..c84813a 100644
--- a/arm/graphing/graph_panel.py
+++ b/arm/graphing/graph_panel.py
@@ -539,7 +539,7 @@ class GraphPanel(panel.Panel):
for i in range((graph_column - 4) / interval_spacing):
loc = (i + 1) * interval_spacing
- time_label = str_tools.get_time_label(loc * interval_sec, decimal_precision)
+ time_label = str_tools.time_label(loc * interval_sec, decimal_precision)
if not units_label:
units_label = time_label[-1]
diff --git a/arm/graphing/resource_stats.py b/arm/graphing/resource_stats.py
index 856c2b7..1bbcfcb 100644
--- a/arm/graphing/resource_stats.py
+++ b/arm/graphing/resource_stats.py
@@ -38,8 +38,8 @@ class ResourceStats(graph_panel.GraphStats):
else:
# memory sizes are converted from MB to B before generating labels
- usage_label = str_tools.get_size_label(last_amount * 1048576, 1)
- avg_label = str_tools.get_size_label(avg * 1048576, 1)
+ usage_label = str_tools.size_label(last_amount * 1048576, 1)
+ avg_label = str_tools.size_label(avg * 1048576, 1)
return "Memory (%s, avg: %s):" % (usage_label, avg_label)
diff --git a/arm/header_panel.py b/arm/header_panel.py
index c0ab850..97a7fb3 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -247,7 +247,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
else:
now = time.time()
- uptime = stem.util.str_tools.get_short_time_label(now - vals.start_time)
+ uptime = stem.util.str_tools.short_time_label(now - vals.start_time)
else:
uptime = ''
@@ -443,7 +443,7 @@ class Sampling(object):
self.version_color = CONFIG['attr.version_status_colors'].get(self.version_status, 'white')
self.pid = pid if pid else ''
- self.start_time = stem.util.system.get_start_time(pid)
+ self.start_time = stem.util.system.start_time(pid)
self.fd_limit = int(fd_limit) if fd_limit.isdigit() else None
try:
@@ -453,7 +453,7 @@ class Sampling(object):
self.tor_cpu = '%0.1f' % (100 * tor_resources.cpu_sample)
self.arm_cpu = '%0.1f' % (100 * self._get_cpu_percentage(last_sampling))
- self.memory = stem.util.str_tools.get_size_label(tor_resources.memory_bytes) if tor_resources.memory_bytes > 0 else 0
+ self.memory = stem.util.str_tools.size_label(tor_resources.memory_bytes) if tor_resources.memory_bytes > 0 else 0
self.memory_percent = '%0.1f' % (100 * tor_resources.memory_percent)
self.hostname = uname_vals[1]
self.platform = '%s %s' % (uname_vals[0], uname_vals[2]) # [platform name] [version]
diff --git a/arm/starter.py b/arm/starter.py
index ea8e17b..fbc9256 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -203,7 +203,7 @@ def _setup_freebsd_chroot(controller, config):
"""
if not config.get('tor.chroot', None) and platform.system() == 'FreeBSD':
- jail_chroot = stem.util.system.get_bsd_jail_path(controller.get_pid(0))
+ jail_chroot = stem.util.system.bsd_jail_path(controller.get_pid(0))
if jail_chroot and os.path.exists(jail_chroot):
log.info('setup.set_freebsd_chroot', path = jail_chroot)
diff --git a/arm/util/tor_config.py b/arm/util/tor_config.py
index 32d0b07..bec1466 100644
--- a/arm/util/tor_config.py
+++ b/arm/util/tor_config.py
@@ -428,7 +428,7 @@ def get_config_location():
raise IOError("unable to query the torrc location")
try:
- tor_cwd = system.get_cwd(tor_pid)
+ tor_cwd = system.cwd(tor_pid)
return tor_prefix + system.expand_path(config_location, tor_cwd)
except IOError as exc:
raise IOError("querying tor's pwd failed because %s" % exc)
@@ -736,9 +736,9 @@ def validate(contents = None):
display_values = tor_values
if value_type == ValueType.SIZE:
- display_values = [str_tools.get_size_label(int(val)) for val in tor_values]
+ display_values = [str_tools.size_label(int(val)) for val in tor_values]
elif value_type == ValueType.TIME:
- display_values = [str_tools.get_time_label(int(val)) for val in tor_values]
+ display_values = [str_tools.time_label(int(val)) for val in tor_values]
issues_found.append((line_number, ValidationError.MISMATCH, ", ".join(display_values)))
diff --git a/arm/util/tracker.py b/arm/util/tracker.py
index 224c99c..b9246a4 100644
--- a/arm/util/tracker.py
+++ b/arm/util/tracker.py
@@ -395,7 +395,7 @@ class Daemon(threading.Thread):
with self._process_lock:
if not self._halt and event_type in (State.INIT, State.RESET):
tor_pid = controller.get_pid(None)
- tor_cmd = system.get_name_by_pid(tor_pid) if tor_pid else None
+ tor_cmd = system.name_by_pid(tor_pid) if tor_pid else None
self._process_pid = tor_pid
self._process_name = tor_cmd if tor_cmd else 'tor'
@@ -418,7 +418,7 @@ class ConnectionTracker(Daemon):
super(ConnectionTracker, self).__init__(rate)
self._connections = []
- self._resolvers = connection.get_system_resolvers()
+ self._resolvers = connection.system_resolvers()
self._custom_resolver = None
# Number of times in a row we've either failed with our current resolver or
diff --git a/run_tests.py b/run_tests.py
index c7482d3..9ac8765 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -44,14 +44,14 @@ def main():
static_check_issues = {}
if stem.util.test_tools.is_pyflakes_available():
- pyflakes_issues = stem.util.test_tools.get_pyflakes_issues(SRC_PATHS)
+ pyflakes_issues = stem.util.test_tools.pyflakes_issues(SRC_PATHS)
for path, issues in pyflakes_issues.items():
for issue in issues:
static_check_issues.setdefault(path, []).append(issue)
if stem.util.test_tools.is_pep8_available():
- pep8_issues = stem.util.test_tools.get_stylistic_issues(
+ pep8_issues = stem.util.test_tools.stylistic_issues(
SRC_PATHS,
check_two_space_indents = True,
check_newlines = True,
1
0

02 Sep '14
commit 308a213009f43588a34c5b44d87de8d467ce9efe
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 17:31:58 2014 -0700
Adding an is_wide() helper for the header panel
Three things make decisions based on if we're showing two columns or not, so
adding a helper to answer it.
---
arm/header_panel.py | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/arm/header_panel.py b/arm/header_panel.py
index 6e1f381..c0ab850 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -51,18 +51,26 @@ class HeaderPanel(panel.Panel, threading.Thread):
tor_controller().add_status_listener(self.reset_listener)
+ def is_wide(self, width = None):
+ """
+ True if we should show two columns of information, False otherwise.
+ """
+
+ if width is None:
+ width = self.get_parent().getmaxyx()[1]
+
+ return width >= MIN_DUAL_COL_WIDTH
+
def get_height(self):
"""
Provides the height of the content, which is dynamically determined by the
panel's maximum width.
"""
- is_wide = self.get_parent().getmaxyx()[1] >= MIN_DUAL_COL_WIDTH
-
if self._vals.is_relay:
- return 4 if is_wide else 6
+ return 4 if self.is_wide() else 6
else:
- return 3 if is_wide else 4
+ return 3 if self.is_wide() else 4
def send_newnym(self):
"""
@@ -74,9 +82,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
# If we're wide then the newnym label in this panel will give an
# indication that the signal was sent. Otherwise use a msg.
- is_wide = self.get_parent().getmaxyx()[1] >= MIN_DUAL_COL_WIDTH
-
- if not is_wide:
+ if not self.is_wide():
arm.popups.show_msg('Requesting a new identity', 1)
def handle_key(self, key):
@@ -134,7 +140,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
def draw(self, width, height):
vals = self._vals # local reference to avoid concurrency concerns
- is_wide = width + 1 >= MIN_DUAL_COL_WIDTH
+ is_wide = self.is_wide(width)
# space available for content
1
0

[arm/master] Testing fixes for renamed functions and header panel
by atagar@torproject.org 02 Sep '14
by atagar@torproject.org 02 Sep '14
02 Sep '14
commit 514913522c74341bfad64e2d6da9939efb2e8b47
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 20:57:01 2014 -0700
Testing fixes for renamed functions and header panel
Oops, didn't update our unit tests as I went along. Also a couple minor
corrections from static checks for our header panel.
---
arm/header_panel.py | 4 +---
test/util/tracker/connection_tracker.py | 4 ++--
test/util/tracker/daemon.py | 6 +++---
test/util/tracker/resource_tracker.py | 6 +++---
4 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/arm/header_panel.py b/arm/header_panel.py
index 97a7fb3..0278285 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -19,7 +19,7 @@ import arm.popups
import arm.starter
import arm.util.tracker
-from stem.control import Listener, State
+from stem.control import Listener
from stem.util import conf, log, str_tools
from util import panel, tor_controller
@@ -358,8 +358,6 @@ class HeaderPanel(panel.Panel, threading.Thread):
last_ran = -1
while not self._halt:
- current_time = time.time()
-
if self.is_paused() or not self._vals.is_connected or (time.time() - last_ran) < UPDATE_RATE:
with self._pause_condition:
if not self._halt:
diff --git a/test/util/tracker/connection_tracker.py b/test/util/tracker/connection_tracker.py
index 0e756de..e6120bf 100644
--- a/test/util/tracker/connection_tracker.py
+++ b/test/util/tracker/connection_tracker.py
@@ -16,7 +16,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('arm.util.tracker.tor_controller')
@patch('arm.util.tracker.connection.get_connections')
@patch('arm.util.tracker.system', Mock(return_value = Mock()))
- @patch('arm.util.tracker.connection.get_system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT]))
+ @patch('arm.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT]))
def test_fetching_connections(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
get_value_mock.return_value = [CONNECTION_1, CONNECTION_2, CONNECTION_3]
@@ -39,7 +39,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('arm.util.tracker.tor_controller')
@patch('arm.util.tracker.connection.get_connections')
@patch('arm.util.tracker.system', Mock(return_value = Mock()))
- @patch('arm.util.tracker.connection.get_system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT, connection.Resolver.LSOF]))
+ @patch('arm.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT, connection.Resolver.LSOF]))
def test_resolver_failover(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
get_value_mock.side_effect = IOError()
diff --git a/test/util/tracker/daemon.py b/test/util/tracker/daemon.py
index 9d409e2..89f6031 100644
--- a/test/util/tracker/daemon.py
+++ b/test/util/tracker/daemon.py
@@ -14,7 +14,7 @@ class TestDaemon(unittest.TestCase):
# properly retrieve the process' pid and name.
tor_controller_mock().get_pid.return_value = 12345
- system_mock.get_name_by_pid.return_value = 'local_tor'
+ system_mock.name_by_pid.return_value = 'local_tor'
daemon = Daemon(0.05)
@@ -23,7 +23,7 @@ class TestDaemon(unittest.TestCase):
self.assertEqual('local_tor', daemon._process_name)
tor_controller_mock().add_status_listener.assert_called_with(daemon._tor_status_listener)
- system_mock.get_name_by_pid.assert_called_with(12345)
+ system_mock.name_by_pid.assert_called_with(12345)
@patch('arm.util.tracker.tor_controller')
@patch('arm.util.tracker.system')
@@ -31,7 +31,7 @@ class TestDaemon(unittest.TestCase):
# Check when we default to 'tor' if unable to determine the process' name.
tor_controller_mock().get_pid.return_value = 12345
- system_mock.get_name_by_pid.return_value = None
+ system_mock.name_by_pid.return_value = None
daemon = Daemon(0.05)
self.assertEqual('tor', daemon._process_name)
diff --git a/test/util/tracker/resource_tracker.py b/test/util/tracker/resource_tracker.py
index 10509cf..64883d9 100644
--- a/test/util/tracker/resource_tracker.py
+++ b/test/util/tracker/resource_tracker.py
@@ -131,9 +131,9 @@ class TestResourceTracker(unittest.TestCase):
self.assertEqual(0.004, memory_in_percent)
@patch('time.time', Mock(return_value = 1388967218.973117))
- @patch('arm.util.tracker.proc.get_stats', Mock(return_value = (1.5, 0.5, 1388967200.9)))
- @patch('arm.util.tracker.proc.get_memory_usage', Mock(return_value = (19300352, 6432)))
- @patch('arm.util.tracker.proc.get_physical_memory', Mock(return_value = 4825088000))
+ @patch('arm.util.tracker.proc.stats', Mock(return_value = (1.5, 0.5, 1388967200.9)))
+ @patch('arm.util.tracker.proc.memory_usage', Mock(return_value = (19300352, 6432)))
+ @patch('arm.util.tracker.proc.physical_memory', Mock(return_value = 4825088000))
def test_resources_via_proc(self):
total_cpu_time, uptime, memory_in_bytes, memory_in_percent = _resources_via_proc(12345)
1
0
commit 730051edd9a3c357eb81c3ebc3d5b9e490e1d9fe
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 20:53:07 2014 -0700
Dropping the pad_str() function
Turns out it's unused. If it wasn't then the buildin str's ljust does the exact
same thing. :)
---
arm/util/ui_tools.py | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/arm/util/ui_tools.py b/arm/util/ui_tools.py
index cfa6ba3..d2a6f43 100644
--- a/arm/util/ui_tools.py
+++ b/arm/util/ui_tools.py
@@ -181,22 +181,6 @@ def get_printable(line, keep_newlines = True):
return line
-def pad_str(msg, size, crop_extra = False):
- """
- Provides the string padded with whitespace to the given length.
-
- Arguments:
- msg - string to be padded
- size - length to be padded to
- crop_extra - crops string if it's longer than the size if true
- """
-
- if crop_extra:
- msg = msg[:size]
-
- return ("%%-%is" % size) % msg
-
-
def draw_box(panel, top, left, width, height, attr=curses.A_NORMAL):
"""
Draws a box in the panel with the given bounds.
1
0

02 Sep '14
commit 666a831342cb1bc9311ae6e8767a10c4fd1dac5c
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 16:49:04 2014 -0700
Dropping get_* prefix from proc functions
Just about all the proc functions started with get_*. Bad habbit from my days
of doing java. Dropping them, with an alias for the old names for backward
compatability.
---
stem/control.py | 1 +
stem/util/proc.py | 50 ++++++++++++++++++++++--------------
test/integ/util/proc.py | 32 ++++++++++++------------
test/unit/util/proc.py | 64 +++++++++++++++++++++++------------------------
4 files changed, 80 insertions(+), 67 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index 8571a7f..7c5d7bd 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -128,6 +128,7 @@ If you're fine with allowing your script to raise exceptions then this can be mo
BaseController - Base controller class asynchronous message handling
|- msg - communicates with the tor process
|- is_alive - reports if our connection to tor is open or closed
+ |- connection_time - time when we last connected or disconnected
|- is_authenticated - checks if we're authenticated to tor
|- connect - connects or reconnects to tor
|- close - shuts down our connection to the tor process
diff --git a/stem/util/proc.py b/stem/util/proc.py
index f9b2a59..ac1f6f6 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -20,18 +20,18 @@ future, use them at your own risk.**
::
is_available - checks if proc utilities can be used on this system
- get_system_start_time - unix timestamp for when the system started
- get_physical_memory - memory available on this system
- get_cwd - provides the current working directory for a process
- get_uid - provides the user id a process is running under
- get_memory_usage - provides the memory usage of a process
- get_stats - queries statistics about a process
- get_file_descriptors_used - number of file descriptors used by a process
- get_connections - provides the connections made by a process
+ system_start_time - unix timestamp for when the system started
+ physical_memory - memory available on this system
+ cwd - provides the current working directory for a process
+ uid - provides the user id a process is running under
+ memory_usage - provides the memory usage of a process
+ stats - queries statistics about a process
+ file_descriptors_used - number of file descriptors used by a process
+ connections - provides the connections made by a process
.. data:: Stat (enum)
- Types of data available via the :func:`~stem.util.proc.get_stats` function.
+ Types of data available via the :func:`~stem.util.proc.stats` function.
============== ===========
Stat Description
@@ -94,7 +94,7 @@ def is_available():
@lru_cache()
-def get_system_start_time():
+def system_start_time():
"""
Provides the unix time (seconds since epoch) when the system started.
@@ -117,7 +117,7 @@ def get_system_start_time():
@lru_cache()
-def get_physical_memory():
+def physical_memory():
"""
Provides the total physical memory on the system in bytes.
@@ -139,7 +139,7 @@ def get_physical_memory():
raise exc
-def get_cwd(pid):
+def cwd(pid):
"""
Provides the current working directory for the given process.
@@ -167,7 +167,7 @@ def get_cwd(pid):
return cwd
-def get_uid(pid):
+def uid(pid):
"""
Provides the user ID the given process is running under.
@@ -192,7 +192,7 @@ def get_uid(pid):
raise exc
-def get_memory_usage(pid):
+def memory_usage(pid):
"""
Provides the memory usage in bytes for the given process.
@@ -225,7 +225,7 @@ def get_memory_usage(pid):
raise exc
-def get_stats(pid, *stat_types):
+def stats(pid, *stat_types):
"""
Provides process specific information. See the :data:`~stem.util.proc.Stat`
enum for valid options.
@@ -281,19 +281,19 @@ def get_stats(pid, *stat_types):
results.append(str(float(stat_comp[14]) / CLOCK_TICKS))
elif stat_type == Stat.START_TIME:
if pid == 0:
- return get_system_start_time()
+ return system_start_time()
else:
# According to documentation, starttime is in field 21 and the unit is
# jiffies (clock ticks). We divide it for clock ticks, then add the
# uptime to get the seconds since the epoch.
p_start_time = float(stat_comp[21]) / CLOCK_TICKS
- results.append(str(p_start_time + get_system_start_time()))
+ results.append(str(p_start_time + system_start_time()))
_log_runtime(parameter, stat_path, start_time)
return tuple(results)
-def get_file_descriptors_used(pid):
+def file_descriptors_used(pid):
"""
Provides the number of file descriptors currently being used by a process.
@@ -318,7 +318,7 @@ def get_file_descriptors_used(pid):
raise IOError("Unable to check number of file descriptors used: %s" % exc)
-def get_connections(pid):
+def connections(pid):
"""
Queries connection related information from the proc contents. This provides
similar results to netstat, lsof, sockstat, and other connection resolution
@@ -524,3 +524,15 @@ def _log_failure(parameter, exc):
"""
log.debug('proc call failed (%s): %s' % (parameter, exc))
+
+# TODO: drop with stem 2.x
+# We renamed our methods to drop a redundant 'get_*' prefix, so alias the old
+# names for backward compatability.
+
+get_system_start_time = system_start_time
+get_physical_memory = physical_memory
+get_cwd = cwd
+get_uid = uid
+get_memory_usage = memory_usage
+get_stats = stats
+get_connections = connections
diff --git a/test/integ/util/proc.py b/test/integ/util/proc.py
index 8b76dd6..cad0114 100644
--- a/test/integ/util/proc.py
+++ b/test/integ/util/proc.py
@@ -12,9 +12,9 @@ from stem.util import proc
class TestProc(unittest.TestCase):
- def test_get_cwd(self):
+ def test_cwd(self):
"""
- Checks that stem.util.proc.get_cwd matches our tor instance's cwd.
+ Checks that stem.util.proc.cwd matches our tor instance's cwd.
"""
if not proc.is_available():
@@ -26,11 +26,11 @@ class TestProc(unittest.TestCase):
runner = test.runner.get_runner()
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
- self.assertEquals(tor_cwd, proc.get_cwd(runner_pid))
+ self.assertEquals(tor_cwd, proc.cwd(runner_pid))
- def test_get_uid(self):
+ def test_uid(self):
"""
- Checks that stem.util.proc.get_uid matches our tor instance's uid.
+ Checks that stem.util.proc.uid matches our tor instance's uid.
"""
if not proc.is_available():
@@ -38,11 +38,11 @@ class TestProc(unittest.TestCase):
return
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(os.geteuid(), proc.get_uid(tor_pid))
+ self.assertEquals(os.geteuid(), proc.uid(tor_pid))
- def test_get_memory_usage(self):
+ def test_memory_usage(self):
"""
- Checks that stem.util.proc.get_memory_usage looks somewhat reasonable.
+ Checks that stem.util.proc.memory_usage looks somewhat reasonable.
"""
if not proc.is_available():
@@ -50,15 +50,15 @@ class TestProc(unittest.TestCase):
return
tor_pid = test.runner.get_runner().get_pid()
- res_size, vir_size = proc.get_memory_usage(tor_pid)
+ res_size, vir_size = proc.memory_usage(tor_pid)
# checks that they're larger than a kilobyte
self.assertTrue(res_size > 1024)
self.assertTrue(vir_size > 1024)
- def test_get_stats(self):
+ def test_stats(self):
"""
- Checks that stem.util.proc.get_stats looks somewhat reasonable.
+ Checks that stem.util.proc.stats looks somewhat reasonable.
"""
if not proc.is_available():
@@ -66,16 +66,16 @@ class TestProc(unittest.TestCase):
return
tor_pid = test.runner.get_runner().get_pid()
- command, utime, stime, start_time = proc.get_stats(tor_pid, 'command', 'utime', 'stime', 'start time')
+ command, utime, stime, start_time = proc.stats(tor_pid, 'command', 'utime', 'stime', 'start time')
self.assertEquals('tor', command)
self.assertTrue(float(utime) > 0)
self.assertTrue(float(stime) >= 0)
- self.assertTrue(float(start_time) > proc.get_system_start_time())
+ self.assertTrue(float(start_time) > proc.system_start_time())
- def test_get_connections(self):
+ def test_connections(self):
"""
- Checks for our control port in the stem.util.proc.get_connections output if
+ Checks for our control port in the stem.util.proc.connections output if
we have one.
"""
@@ -95,7 +95,7 @@ class TestProc(unittest.TestCase):
with runner.get_tor_socket():
tor_pid = test.runner.get_runner().get_pid()
- for conn in proc.get_connections(tor_pid):
+ for conn in proc.connections(tor_pid):
if ('127.0.0.1', test.runner.CONTROL_PORT) == conn[:2]:
return
diff --git a/test/unit/util/proc.py b/test/unit/util/proc.py
index 1786a99..c8defd7 100644
--- a/test/unit/util/proc.py
+++ b/test/unit/util/proc.py
@@ -17,45 +17,45 @@ except ImportError:
class TestProc(unittest.TestCase):
@patch('stem.util.proc._get_line')
- def test_get_system_start_time(self, get_line_mock):
+ def test_system_start_time(self, get_line_mock):
"""
- Tests the get_system_start_time function.
+ Tests the system_start_time function.
"""
get_line_mock.side_effect = lambda *params: {
('/proc/stat', 'btime', 'system start time'): 'btime 1001001',
}[params]
- self.assertEquals(1001001, proc.get_system_start_time())
+ self.assertEquals(1001001, proc.system_start_time())
@patch('stem.util.proc._get_line')
- def test_get_physical_memory(self, get_line_mock):
+ def test_physical_memory(self, get_line_mock):
"""
- Tests the get_physical_memory function.
+ Tests the physical_memory function.
"""
get_line_mock.side_effect = lambda *params: {
('/proc/meminfo', 'MemTotal:', 'system physical memory'): 'MemTotal: 12345 kB',
}[params]
- self.assertEquals((12345 * 1024), proc.get_physical_memory())
+ self.assertEquals((12345 * 1024), proc.physical_memory())
@patch('os.readlink')
- def test_get_cwd(self, readlink_mock):
+ def test_cwd(self, readlink_mock):
"""
- Tests the get_cwd function with a given pid.
+ Tests the cwd function with a given pid.
"""
readlink_mock.side_effect = lambda param: {
'/proc/24019/cwd': '/home/directory/TEST'
}[param]
- self.assertEquals('/home/directory/TEST', proc.get_cwd(24019))
+ self.assertEquals('/home/directory/TEST', proc.cwd(24019))
@patch('stem.util.proc._get_line')
- def test_get_uid(self, get_line_mock):
+ def test_uid(self, get_line_mock):
"""
- Tests the get_uid function with a given pid.
+ Tests the uid function with a given pid.
"""
for test_value in [(24019, 11111), (0, 22222)]:
@@ -65,12 +65,12 @@ class TestProc(unittest.TestCase):
('/proc/%s/status' % pid, 'Uid:', 'uid'): 'Uid: %s' % uid,
}[params]
- self.assertEquals(uid, proc.get_uid(pid))
+ self.assertEquals(uid, proc.uid(pid))
@patch('stem.util.proc._get_lines')
- def test_get_memory_usage(self, get_lines_mock):
+ def test_memory_usage(self, get_lines_mock):
"""
- Tests the get_memory_usage function with a given pid.
+ Tests the memory_usage function with a given pid.
"""
get_lines_mock.side_effect = lambda *params: {
@@ -78,14 +78,14 @@ class TestProc(unittest.TestCase):
{'VmRSS:': 'VmRSS: 100 kB', 'VmSize:': 'VmSize: 1800 kB'}
}[params]
- self.assertEqual((0, 0), proc.get_memory_usage(0))
- self.assertEqual((100 * 1024, 1800 * 1024), proc.get_memory_usage(1111))
+ self.assertEqual((0, 0), proc.memory_usage(0))
+ self.assertEqual((100 * 1024, 1800 * 1024), proc.memory_usage(1111))
@patch('stem.util.proc._get_line')
- @patch('stem.util.proc.get_system_start_time', Mock(return_value = 10))
- def test_get_stats(self, get_line_mock):
+ @patch('stem.util.proc.system_start_time', Mock(return_value = 10))
+ def test_stats(self, get_line_mock):
"""
- Tests get_stats() with all combinations of stat_type arguments.
+ Tests stats() with all combinations of stat_type arguments.
"""
# list of all combinations of args with respective return values
@@ -105,7 +105,7 @@ class TestProc(unittest.TestCase):
(stat_path, '24062', 'process '): stat
}[params]
- self.assertEquals((), proc.get_stats(24062))
+ self.assertEquals((), proc.stats(24062))
for stats in stat_combinations:
# the stats variable is...
@@ -120,7 +120,7 @@ class TestProc(unittest.TestCase):
(stat_path, '24062', 'process %s' % ', '.join(args)): stat
}[params]
- self.assertEquals(response, proc.get_stats(24062, *args))
+ self.assertEquals(response, proc.stats(24062, *args))
# tests the case where pid = 0
@@ -141,18 +141,18 @@ class TestProc(unittest.TestCase):
('/proc/0/stat', '0', 'process %s' % ', '.join(args)): stat
}[params]
- self.assertEquals(response, proc.get_stats(0, *args))
+ self.assertEquals(response, proc.stats(0, *args))
@patch('os.listdir')
- def test_get_file_descriptors_used(self, listdir_mock):
+ def test_file_descriptors_used(self, listdir_mock):
"""
- Tests the get_file_descriptors_used function.
+ Tests the file_descriptors_used function.
"""
# check that we reject bad pids
for arg in (None, -100, 'hello',):
- self.assertRaises(IOError, proc.get_file_descriptors_used, arg)
+ self.assertRaises(IOError, proc.file_descriptors_used, arg)
# when proc directory doesn't exist
@@ -160,7 +160,7 @@ class TestProc(unittest.TestCase):
listdir_mock.side_effect = OSError(error_msg)
try:
- proc.get_file_descriptors_used(2118)
+ proc.file_descriptors_used(2118)
self.fail("We should raise when listdir() fails")
except IOError as exc:
expected = "Unable to check number of file descriptors used: %s" % error_msg
@@ -171,15 +171,15 @@ class TestProc(unittest.TestCase):
listdir_mock.return_value = ['0', '1', '2', '3', '4', '5']
listdir_mock.side_effect = None
- self.assertEqual(6, proc.get_file_descriptors_used(2118))
- self.assertEqual(6, proc.get_file_descriptors_used('2118'))
+ self.assertEqual(6, proc.file_descriptors_used(2118))
+ self.assertEqual(6, proc.file_descriptors_used('2118'))
@patch('os.listdir')
@patch('os.readlink')
@patch('stem.util.proc.open', create = True)
- def test_get_connections(self, open_mock, readlink_mock, listdir_mock):
+ def test_connections(self, open_mock, readlink_mock, listdir_mock):
"""
- Tests the get_connections function.
+ Tests the connections function.
"""
pid = 1111
@@ -204,11 +204,11 @@ class TestProc(unittest.TestCase):
}[param]
# tests the edge case of pid = 0
- self.assertEquals([], proc.get_connections(0))
+ self.assertEquals([], proc.connections(0))
expected_results = [
('17.17.17.17', 4369, '34.34.34.34', 8738, 'tcp'),
('187.187.187.187', 48059, '204.204.204.204', 52428, 'udp'),
]
- self.assertEquals(expected_results, proc.get_connections(pid))
+ self.assertEquals(expected_results, proc.connections(pid))
1
0

[stem/master] Renaming get_system_resolvers() to system_resolvers()
by atagar@torproject.org 02 Sep '14
by atagar@torproject.org 02 Sep '14
02 Sep '14
commit abe6fc9d9caee79bcb3021d9942204e3ce63c54b
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 20:24:41 2014 -0700
Renaming get_system_resolvers() to system_resolvers()
---
docs/tutorials/east_of_the_sun.rst | 4 ++--
stem/util/connection.py | 18 +++++++++++++++---
stem/util/proc.py | 5 ++---
stem/util/system.py | 5 ++---
test/integ/util/connection.py | 4 ++--
test/unit/util/connection.py | 20 ++++++++++----------
6 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/docs/tutorials/east_of_the_sun.rst b/docs/tutorials/east_of_the_sun.rst
index fa7635b..13ede2d 100644
--- a/docs/tutorials/east_of_the_sun.rst
+++ b/docs/tutorials/east_of_the_sun.rst
@@ -37,10 +37,10 @@ simple script that dumps Tor's present connections.
import sys
- from stem.util.connection import get_connections, get_system_resolvers
+ from stem.util.connection import get_connections, system_resolvers
from stem.util.system import pid_by_name
- resolvers = get_system_resolvers()
+ resolvers = system_resolvers()
if not resolvers:
print "Stem doesn't support any connection resolvers on our platform."
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 0c5b744..09acdeb 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -4,10 +4,12 @@
"""
Connection and networking based utility functions.
+**Module Overview:**
+
::
get_connections - quieries the connections belonging to a given process
- get_system_resolvers - provides connection resolution methods that are likely to be available
+ system_resolvers - provides connection resolution methods that are likely to be available
port_usage - brief description of the common usage for a port
is_valid_ipv4_address - checks if a string is a valid IPv4 address
@@ -130,7 +132,7 @@ RESOLVER_FILTER = {
def get_connections(resolver, process_pid = None, process_name = None):
"""
Retrieves a list of the current connections for a given process. The provides
- a list of Connection instances, which have four attributes...
+ a list of Connection instances, which have five attributes...
* local_address (str)
* local_port (int)
@@ -230,12 +232,16 @@ def get_connections(resolver, process_pid = None, process_name = None):
return connections
-def get_system_resolvers(system = None):
+def system_resolvers(system = None):
"""
Provides the types of connection resolvers likely to be available on this platform.
.. versionadded:: 1.1.0
+ .. versionchanged:: 1.3.0
+ Renamed from get_system_resolvers() to system_resolvers(). The old name
+ still works as an alias, but will be dropped in Stem version 2.0.0.
+
:param str system: system to get resolvers for, this is determined by
platform.system() if not provided
@@ -619,3 +625,9 @@ def _cryptovariables_equal(x, y):
return (
_hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, x) ==
_hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, y))
+
+# TODO: drop with stem 2.x
+# We renamed our methods to drop a redundant 'get_*' prefix, so alias the old
+# names for backward compatability.
+
+get_system_resolvers = system_resolvers
diff --git a/stem/util/proc.py b/stem/util/proc.py
index b05d283..85a7501 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -15,9 +15,8 @@ Dave Daeschler, Giampaolo Rodola' and is under the BSD license.
**These functions are not being vended to stem users. They may change in the
future, use them at your own risk.**
-.. deprecated:: 1.3.0
- Many functions were previously named with a get_* prefix. Those names are
- now aliases, and will be dropped in Stem version 2.0.0.
+**Note:** Many functions were previously named with a get_* prefix. Those names
+are now aliases, and will be dropped in Stem version 2.0.0.
**Module Overview:**
diff --git a/stem/util/system.py b/stem/util/system.py
index 89eac3f..47023f4 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -6,9 +6,8 @@ Helper functions for working with the underlying system. These are mostly os
dependent, only working on linux, osx, and bsd. In almost all cases they're
best-effort, providing **None** if the lookup fails.
-.. deprecated:: 1.3.0
- Many functions were previously named with a get_* prefix. Those names are
- now aliases, and will be dropped in Stem version 2.0.0.
+**Note:** Many functions were previously named with a get_* prefix. Those names
+are now aliases, and will be dropped in Stem version 2.0.0.
**Module Overview:**
diff --git a/test/integ/util/connection.py b/test/integ/util/connection.py
index 8883be2..589026a 100644
--- a/test/integ/util/connection.py
+++ b/test/integ/util/connection.py
@@ -7,7 +7,7 @@ import unittest
import test.runner
-from stem.util.connection import get_connections, get_system_resolvers
+from stem.util.connection import get_connections, system_resolvers
class TestConnection(unittest.TestCase):
@@ -21,7 +21,7 @@ class TestConnection(unittest.TestCase):
test.runner.skip(self, '(DisableDebuggerAttachment is set)')
return
- for resolver in get_system_resolvers():
+ for resolver in system_resolvers():
with runner.get_tor_socket():
tor_pid = test.runner.get_runner().get_pid()
connections = get_connections(resolver, process_pid = tor_pid)
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index f44a851..0ae6f9b 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -107,32 +107,32 @@ BSD_PROCSTAT_OUTPUT = """\
class TestConnection(unittest.TestCase):
@patch('stem.util.system.is_available')
@patch('stem.util.proc.is_available')
- def test_get_system_resolvers(self, proc_mock, is_available_mock):
+ def test_system_resolvers(self, proc_mock, is_available_mock):
"""
- Checks the get_system_resolvers function.
+ Checks the system_resolvers function.
"""
is_available_mock.return_value = True
proc_mock.return_value = False
- self.assertEqual([], stem.util.connection.get_system_resolvers('Windows'))
- self.assertEqual([Resolver.LSOF], stem.util.connection.get_system_resolvers('Darwin'))
- self.assertEqual([Resolver.LSOF], stem.util.connection.get_system_resolvers('OpenBSD'))
- self.assertEqual([Resolver.BSD_SOCKSTAT, Resolver.BSD_PROCSTAT, Resolver.LSOF], stem.util.connection.get_system_resolvers('FreeBSD'))
- self.assertEqual([Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.get_system_resolvers('Linux'))
+ self.assertEqual([], stem.util.connection.system_resolvers('Windows'))
+ self.assertEqual([Resolver.LSOF], stem.util.connection.system_resolvers('Darwin'))
+ self.assertEqual([Resolver.LSOF], stem.util.connection.system_resolvers('OpenBSD'))
+ self.assertEqual([Resolver.BSD_SOCKSTAT, Resolver.BSD_PROCSTAT, Resolver.LSOF], stem.util.connection.system_resolvers('FreeBSD'))
+ self.assertEqual([Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.system_resolvers('Linux'))
proc_mock.return_value = True
- self.assertEqual([Resolver.PROC, Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.get_system_resolvers('Linux'))
+ self.assertEqual([Resolver.PROC, Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.system_resolvers('Linux'))
# check that calling without an argument is equivilant to calling for this
# platform
- self.assertEqual(stem.util.connection.get_system_resolvers(platform.system()), stem.util.connection.get_system_resolvers())
+ self.assertEqual(stem.util.connection.system_resolvers(platform.system()), stem.util.connection.system_resolvers())
# check that lacking commands in our PATH drops them from the results
is_available_mock.return_value = False
- self.assertEqual([Resolver.PROC], stem.util.connection.get_system_resolvers('Linux'))
+ self.assertEqual([Resolver.PROC], stem.util.connection.system_resolvers('Linux'))
def test_port_usage(self):
"""
1
0

02 Sep '14
commit 87f9549091d4050578b963238179a584b2936491
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 18:02:49 2014 -0700
Dropping get_* prefix from system functions
---
docs/change_log.rst | 10 +--
docs/tutorials/east_of_the_sun.rst | 4 +-
stem/connection.py | 14 ++--
stem/control.py | 8 +-
stem/util/connection.py | 2 +-
stem/util/proc.py | 4 +
stem/util/system.py | 67 +++++++++++------
test/integ/util/system.py | 142 ++++++++++++++++++------------------
test/unit/control/controller.py | 6 +-
test/unit/response/protocolinfo.py | 2 +-
test/unit/util/connection.py | 2 +-
test/unit/util/system.py | 120 +++++++++++++++---------------
12 files changed, 202 insertions(+), 179 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index 24e39f0..dbb5581 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -147,12 +147,12 @@ and a myriad of smaller improvements and fixes.
* Connection resolution via the :func:`~stem.util.connection.get_connections` function (:trac:`7910`)
* :func:`~stem.util.system.set_process_name` inserted spaces between characters (:trac:`8631`)
- * :func:`~stem.util.system.get_pid_by_name` can now pull for all processes with a given name
+ * :func:`~stem.util.system.pid_by_name` can now pull for all processes with a given name
* :func:`~stem.util.system.call` ignored the subprocess' exit status
- * Added :func:`stem.util.system.get_name_by_pid`
- * Added :func:`stem.util.system.get_user`
- * Added :func:`stem.util.system.get_start_time`
- * Added :func:`stem.util.system.get_bsd_jail_path`
+ * Added :func:`stem.util.system.name_by_pid`
+ * Added :func:`stem.util.system.user`
+ * Added :func:`stem.util.system.start_time`
+ * Added :func:`stem.util.system.bsd_jail_path`
* Added :func:`stem.util.system.is_tarfile`
* Added :func:`stem.util.connection.is_private_address`
diff --git a/docs/tutorials/east_of_the_sun.rst b/docs/tutorials/east_of_the_sun.rst
index 374275e..fa7635b 100644
--- a/docs/tutorials/east_of_the_sun.rst
+++ b/docs/tutorials/east_of_the_sun.rst
@@ -38,7 +38,7 @@ simple script that dumps Tor's present connections.
import sys
from stem.util.connection import get_connections, get_system_resolvers
- from stem.util.system import get_pid_by_name
+ from stem.util.system import pid_by_name
resolvers = get_system_resolvers()
@@ -49,7 +49,7 @@ simple script that dumps Tor's present connections.
picked_resolver = resolvers[0] # lets just opt for the first
print "Our platform supports connection resolution via: %s (picked %s)" % (', '.join(resolvers), picked_resolver)
- tor_pids = get_pid_by_name('tor', multiple = True)
+ tor_pids = pid_by_name('tor', multiple = True)
if not tor_pids:
print "Unable to get tor's pid. Is it running?"
diff --git a/stem/connection.py b/stem/connection.py
index cc28fa5..a38422b 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -1012,7 +1012,7 @@ def get_protocolinfo(controller):
# attempt to expand relative cookie paths
if protocolinfo_response.cookie_path:
- _expand_cookie_path(protocolinfo_response, stem.util.system.get_pid_by_name, 'tor')
+ _expand_cookie_path(protocolinfo_response, stem.util.system.pid_by_name, 'tor')
# attempt to expand relative cookie paths via the control port or socket file
@@ -1023,10 +1023,10 @@ def get_protocolinfo(controller):
if isinstance(control_socket, stem.socket.ControlPort):
if control_socket.get_address() == '127.0.0.1':
- pid_method = stem.util.system.get_pid_by_port
+ pid_method = stem.util.system.pid_by_port
_expand_cookie_path(protocolinfo_response, pid_method, control_socket.get_port())
elif isinstance(control_socket, stem.socket.ControlSocketFile):
- pid_method = stem.util.system.get_pid_by_open_file
+ pid_method = stem.util.system.pid_by_open_file
_expand_cookie_path(protocolinfo_response, pid_method, control_socket.get_socket_path())
return protocolinfo_response
@@ -1102,7 +1102,7 @@ def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg)
if not tor_pid:
raise IOError('pid lookup failed')
- tor_cwd = stem.util.system.get_cwd(tor_pid)
+ tor_cwd = stem.util.system.cwd(tor_pid)
if not tor_cwd:
raise IOError('cwd lookup failed')
@@ -1110,9 +1110,9 @@ def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg)
cookie_path = stem.util.system.expand_path(cookie_path, tor_cwd)
except IOError as exc:
resolver_labels = {
- stem.util.system.get_pid_by_name: ' by name',
- stem.util.system.get_pid_by_port: ' by port',
- stem.util.system.get_pid_by_open_file: ' by socket file',
+ stem.util.system.pid_by_name: ' by name',
+ stem.util.system.pid_by_port: ' by port',
+ stem.util.system.pid_by_open_file: ' by socket file',
}
pid_resolver_label = resolver_labels.get(pid_resolver, '')
diff --git a/stem/control.py b/stem/control.py
index 7c5d7bd..e5f4769 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1242,7 +1242,7 @@ class Controller(BaseController):
pid = self.get_pid(None)
if pid:
- user = stem.util.system.get_user(pid)
+ user = stem.util.system.user(pid)
if user:
self._set_cache({'user': user})
@@ -1290,15 +1290,15 @@ class Controller(BaseController):
pid = int(pid_file_contents)
if not pid:
- pid = stem.util.system.get_pid_by_name('tor')
+ pid = stem.util.system.pid_by_name('tor')
if not pid:
control_socket = self.get_socket()
if isinstance(control_socket, stem.socket.ControlPort):
- pid = stem.util.system.get_pid_by_port(control_socket.get_port())
+ pid = stem.util.system.pid_by_port(control_socket.get_port())
elif isinstance(control_socket, stem.socket.ControlSocketFile):
- pid = stem.util.system.get_pid_by_open_file(control_socket.get_socket_path())
+ pid = stem.util.system.pid_by_open_file(control_socket.get_socket_path())
if pid:
self._set_cache({'pid': pid})
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 461f40a..0c5b744 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -172,7 +172,7 @@ def get_connections(resolver, process_pid = None, process_name = None):
raise ValueError('%s resolution requires a pid' % resolver)
if resolver == Resolver.PROC:
- return [Connection(*conn) for conn in stem.util.proc.get_connections(process_pid)]
+ return [Connection(*conn) for conn in stem.util.proc.connections(process_pid)]
resolver_command = RESOLVER_COMMAND[resolver].format(pid = process_pid)
diff --git a/stem/util/proc.py b/stem/util/proc.py
index ac1f6f6..b05d283 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -15,6 +15,10 @@ Dave Daeschler, Giampaolo Rodola' and is under the BSD license.
**These functions are not being vended to stem users. They may change in the
future, use them at your own risk.**
+.. deprecated:: 1.3.0
+ Many functions were previously named with a get_* prefix. Those names are
+ now aliases, and will be dropped in Stem version 2.0.0.
+
**Module Overview:**
::
diff --git a/stem/util/system.py b/stem/util/system.py
index b42a03f..89eac3f 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -6,6 +6,10 @@ Helper functions for working with the underlying system. These are mostly os
dependent, only working on linux, osx, and bsd. In almost all cases they're
best-effort, providing **None** if the lookup fails.
+.. deprecated:: 1.3.0
+ Many functions were previously named with a get_* prefix. Those names are
+ now aliases, and will be dropped in Stem version 2.0.0.
+
**Module Overview:**
::
@@ -18,15 +22,15 @@ best-effort, providing **None** if the lookup fails.
is_running - determines if a given process is running
call - runs the given system command and provides back the results
- get_name_by_pid - gets the name for a process by the given pid
- get_pid_by_name - gets the pid for a process by the given name
- get_pid_by_port - gets the pid for a process listening to a given port
- get_pid_by_open_file - gets the pid for the process with an open file
- get_cwd - provides the current working directory for a given process
- get_user - provides the user a process is running under
- get_start_time - provides the unix timestamp when the process started
- get_bsd_jail_id - provides the BSD jail id a given process is running within
- get_bsd_jail_path - provides the path of the given BSD jail
+ name_by_pid - gets the name for a process by the given pid
+ pid_by_name - gets the pid for a process by the given name
+ pid_by_port - gets the pid for a process listening to a given port
+ pid_by_open_file - gets the pid for the process with an open file
+ cwd - provides the current working directory for a given process
+ user - provides the user a process is running under
+ start_time - provides the unix timestamp when the process started
+ bsd_jail_id - provides the BSD jail id a given process is running within
+ bsd_jail_path - provides the path of the given BSD jail
is_tarfile - checks if the given path is a tarball
expand_path - expands relative paths and ~ entries
@@ -233,7 +237,7 @@ def is_running(command):
return None
-def get_name_by_pid(pid):
+def name_by_pid(pid):
"""
Attempts to determine the name a given process is running under (not
including arguments). This uses...
@@ -252,7 +256,7 @@ def get_name_by_pid(pid):
if stem.util.proc.is_available():
try:
- process_name = stem.util.proc.get_stats(pid, stem.util.proc.Stat.COMMAND)[0]
+ process_name = stem.util.proc.stats(pid, stem.util.proc.Stat.COMMAND)[0]
except IOError:
pass
@@ -273,7 +277,7 @@ def get_name_by_pid(pid):
return process_name
-def get_pid_by_name(process_name, multiple = False):
+def pid_by_name(process_name, multiple = False):
"""
Attempts to determine the process id for a running process, using...
@@ -421,7 +425,7 @@ def get_pid_by_name(process_name, multiple = False):
return [] if multiple else None
-def get_pid_by_port(port):
+def pid_by_port(port):
"""
Attempts to determine the process id for a process with the given port,
using...
@@ -541,7 +545,7 @@ def get_pid_by_port(port):
return None # all queries failed
-def get_pid_by_open_file(path):
+def pid_by_open_file(path):
"""
Attempts to determine the process id for a process with the given open file,
using...
@@ -579,7 +583,7 @@ def get_pid_by_open_file(path):
return None # all queries failed
-def get_cwd(pid):
+def cwd(pid):
"""
Provides the working directory of the given process.
@@ -592,12 +596,12 @@ def get_cwd(pid):
# try fetching via the proc contents if it's available
if stem.util.proc.is_available():
try:
- return stem.util.proc.get_cwd(pid)
+ return stem.util.proc.cwd(pid)
except IOError:
pass
# Fall back to a pwdx query. This isn't available on BSD.
- logging_prefix = 'get_cwd(%s):' % pid
+ logging_prefix = 'cwd(%s):' % pid
if is_available('pwdx'):
# pwdx results are of the form:
@@ -648,7 +652,7 @@ def get_cwd(pid):
return None # all queries failed
-def get_user(pid):
+def user(pid):
"""
Provides the user a process is running under.
@@ -665,7 +669,7 @@ def get_user(pid):
try:
import pwd # only available on unix platforms
- uid = stem.util.proc.get_uid(pid)
+ uid = stem.util.proc.uid(pid)
if uid and uid.isdigit():
return pwd.getpwuid(int(uid)).pw_name
@@ -681,7 +685,7 @@ def get_user(pid):
return None
-def get_start_time(pid):
+def start_time(pid):
"""
Provides the unix timestamp when the given process started.
@@ -696,7 +700,7 @@ def get_start_time(pid):
if stem.util.proc.is_available():
try:
- return float(stem.util.proc.get_stats(pid, stem.util.proc.Stat.START_TIME)[0])
+ return float(stem.util.proc.stats(pid, stem.util.proc.Stat.START_TIME)[0])
except IOError:
pass
@@ -712,7 +716,7 @@ def get_start_time(pid):
return None
-def get_bsd_jail_id(pid):
+def bsd_jail_id(pid):
"""
Gets the jail id for a process. These seem to only exist for FreeBSD (this
style for jails does not exist on Linux, OSX, or OpenBSD).
@@ -742,12 +746,12 @@ def get_bsd_jail_id(pid):
if os_name == 'FreeBSD':
log.warn('Unable to get the jail id for process %s.' % pid)
else:
- log.debug('get_bsd_jail_id(%s): jail ids do not exist on %s' % (pid, os_name))
+ log.debug('bsd_jail_id(%s): jail ids do not exist on %s' % (pid, os_name))
return 0
-def get_bsd_jail_path(jid):
+def bsd_jail_path(jid):
"""
Provides the path of the given FreeBSD jail.
@@ -1066,3 +1070,18 @@ def _set_proc_title(process_name):
# AttributeError: dlsym(0x7fff6a41d1e0, setproctitle): symbol not found
pass
+
+
+# TODO: drop with stem 2.x
+# We renamed our methods to drop a redundant 'get_*' prefix, so alias the old
+# names for backward compatability.
+
+get_name_by_pid = name_by_pid
+get_pid_by_name = pid_by_name
+get_pid_by_port = pid_by_port
+get_pid_by_open_file = pid_by_open_file
+get_cwd = cwd
+get_user = user
+get_start_time = start_time
+get_bsd_jail_id = bsd_jail_id
+get_bsd_jail_path = bsd_jail_path
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 69b7c78..c075a27 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -76,9 +76,9 @@ class TestSystem(unittest.TestCase):
self.assertTrue(stem.util.system.is_running('tor'))
self.assertFalse(stem.util.system.is_running('blarg_and_stuff'))
- def test_get_pid_by_name(self):
+ def test_pid_by_name(self):
"""
- Checks general usage of the stem.util.system.get_pid_by_name function. This
+ Checks general usage of the stem.util.system.pid_by_name function. This
will fail if there's other tor instances running.
"""
@@ -90,12 +90,12 @@ class TestSystem(unittest.TestCase):
return
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
- self.assertEquals(None, stem.util.system.get_pid_by_name('blarg_and_stuff'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
+ self.assertEquals(None, stem.util.system.pid_by_name('blarg_and_stuff'))
- def test_get_pid_by_name_pgrep(self):
+ def test_pid_by_name_pgrep(self):
"""
- Tests the get_pid_by_name function with a pgrep response.
+ Tests the pid_by_name function with a pgrep response.
"""
if self._is_extra_tor_running():
@@ -113,11 +113,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_pidof(self):
+ def test_pid_by_name_pidof(self):
"""
- Tests the get_pid_by_name function with a pidof response.
+ Tests the pid_by_name function with a pidof response.
"""
if self._is_extra_tor_running():
@@ -135,11 +135,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_ps_linux(self):
+ def test_pid_by_name_ps_linux(self):
"""
- Tests the get_pid_by_name function with the linux variant of ps.
+ Tests the pid_by_name function with the linux variant of ps.
"""
if self._is_extra_tor_running():
@@ -160,11 +160,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_ps_bsd(self):
+ def test_pid_by_name_ps_bsd(self):
"""
- Tests the get_pid_by_name function with the bsd variant of ps.
+ Tests the pid_by_name function with the bsd variant of ps.
"""
if self._is_extra_tor_running():
@@ -185,11 +185,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_lsof(self):
+ def test_pid_by_name_lsof(self):
"""
- Tests the get_pid_by_name function with a lsof response.
+ Tests the pid_by_name function with a lsof response.
"""
runner = test.runner.get_runner()
@@ -211,14 +211,14 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
our_tor_pid = test.runner.get_runner().get_pid()
- all_tor_pids = stem.util.system.get_pid_by_name('tor', multiple = True)
+ all_tor_pids = stem.util.system.pid_by_name('tor', multiple = True)
if len(all_tor_pids) == 1:
self.assertEquals(our_tor_pid, all_tor_pids[0])
- def test_get_pid_by_port(self):
+ def test_pid_by_port(self):
"""
- Checks general usage of the stem.util.system.get_pid_by_port function.
+ Checks general usage of the stem.util.system.pid_by_port function.
"""
runner = test.runner.get_runner()
@@ -241,12 +241,12 @@ class TestSystem(unittest.TestCase):
return
tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(tor_port))
- self.assertEquals(None, stem.util.system.get_pid_by_port(99999))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(tor_port))
+ self.assertEquals(None, stem.util.system.pid_by_port(99999))
- def test_get_pid_by_port_netstat(self):
+ def test_pid_by_port_netstat(self):
"""
- Tests the get_pid_by_port function with a netstat response.
+ Tests the pid_by_port function with a netstat response.
"""
runner = test.runner.get_runner()
@@ -271,11 +271,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(test.runner.CONTROL_PORT))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(test.runner.CONTROL_PORT))
- def test_get_pid_by_port_sockstat(self):
+ def test_pid_by_port_sockstat(self):
"""
- Tests the get_pid_by_port function with a sockstat response.
+ Tests the pid_by_port function with a sockstat response.
"""
runner = test.runner.get_runner()
@@ -300,11 +300,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(test.runner.CONTROL_PORT))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(test.runner.CONTROL_PORT))
- def test_get_pid_by_port_lsof(self):
+ def test_pid_by_port_lsof(self):
"""
- Tests the get_pid_by_port function with a lsof response.
+ Tests the pid_by_port function with a lsof response.
"""
runner = test.runner.get_runner()
@@ -329,24 +329,24 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(test.runner.CONTROL_PORT))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(test.runner.CONTROL_PORT))
- def test_get_pid_by_open_file(self):
+ def test_pid_by_open_file(self):
"""
- Checks the stem.util.system.get_pid_by_open_file function.
+ Checks the stem.util.system.pid_by_open_file function.
"""
# check a directory that exists, but isn't claimed by any application
tmpdir = tempfile.mkdtemp()
- self.assertEquals(None, stem.util.system.get_pid_by_open_file(tmpdir))
+ self.assertEquals(None, stem.util.system.pid_by_open_file(tmpdir))
# check a directory that doesn't exist
os.rmdir(tmpdir)
- self.assertEquals(None, stem.util.system.get_pid_by_open_file(tmpdir))
+ self.assertEquals(None, stem.util.system.pid_by_open_file(tmpdir))
- def test_get_cwd(self):
+ def test_cwd(self):
"""
- Checks general usage of the stem.util.system.get_cwd function.
+ Checks general usage of the stem.util.system.cwd function.
"""
runner = test.runner.get_runner()
@@ -359,12 +359,12 @@ class TestSystem(unittest.TestCase):
return
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
- self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
- self.assertEquals(None, stem.util.system.get_cwd(99999))
+ self.assertEquals(tor_cwd, stem.util.system.cwd(runner_pid))
+ self.assertEquals(None, stem.util.system.cwd(99999))
- def test_get_cwd_pwdx(self):
+ def test_cwd_pwdx(self):
"""
- Tests the get_pid_by_cwd function with a pwdx response.
+ Tests the pid_by_cwd function with a pwdx response.
"""
runner = test.runner.get_runner()
@@ -386,11 +386,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
- self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
+ self.assertEquals(tor_cwd, stem.util.system.cwd(runner_pid))
- def test_get_cwd_lsof(self):
+ def test_cwd_lsof(self):
"""
- Tests the get_pid_by_cwd function with a lsof response.
+ Tests the pid_by_cwd function with a lsof response.
"""
runner = test.runner.get_runner()
@@ -412,20 +412,20 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
- self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
+ self.assertEquals(tor_cwd, stem.util.system.cwd(runner_pid))
- def test_get_user_none(self):
+ def test_user_none(self):
"""
- Tests the get_user function when the process doesn't exist.
+ Tests the user function when the process doesn't exist.
"""
- self.assertEqual(None, stem.util.system.get_user(None))
- self.assertEqual(None, stem.util.system.get_user(-5))
- self.assertEqual(None, stem.util.system.get_start_time(98765))
+ self.assertEqual(None, stem.util.system.user(None))
+ self.assertEqual(None, stem.util.system.user(-5))
+ self.assertEqual(None, stem.util.system.start_time(98765))
- def test_get_user_proc(self):
+ def test_user_proc(self):
"""
- Tests the get_user function with a proc response.
+ Tests the user function with a proc response.
"""
if not stem.util.proc.is_available():
@@ -440,12 +440,12 @@ class TestSystem(unittest.TestCase):
# we started our tor process so it should be running with the same user
pid = test.runner.get_runner().get_pid()
- self.assertTrue(getpass.getuser(), stem.util.system.get_user(pid))
+ self.assertTrue(getpass.getuser(), stem.util.system.user(pid))
@patch('stem.util.proc.is_available', Mock(return_value = False))
- def test_get_user_ps(self):
+ def test_user_ps(self):
"""
- Tests the get_user function with a ps response.
+ Tests the user function with a ps response.
"""
if not stem.util.system.is_available('ps'):
@@ -453,20 +453,20 @@ class TestSystem(unittest.TestCase):
return
pid = test.runner.get_runner().get_pid()
- self.assertTrue(getpass.getuser(), stem.util.system.get_user(pid))
+ self.assertTrue(getpass.getuser(), stem.util.system.user(pid))
- def test_get_start_time_none(self):
+ def test_start_time_none(self):
"""
- Tests the get_start_time function when the process doesn't exist.
+ Tests the start_time function when the process doesn't exist.
"""
- self.assertEqual(None, stem.util.system.get_start_time(None))
- self.assertEqual(None, stem.util.system.get_start_time(-5))
- self.assertEqual(None, stem.util.system.get_start_time(98765))
+ self.assertEqual(None, stem.util.system.start_time(None))
+ self.assertEqual(None, stem.util.system.start_time(-5))
+ self.assertEqual(None, stem.util.system.start_time(98765))
- def test_get_start_time_proc(self):
+ def test_start_time_proc(self):
"""
- Tests the get_start_time function with a proc response.
+ Tests the start_time function with a proc response.
"""
if not stem.util.proc.is_available():
@@ -479,12 +479,12 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
pid = test.runner.get_runner().get_pid()
- self.assertTrue(stem.util.system.get_start_time(pid) >= 0)
+ self.assertTrue(stem.util.system.start_time(pid) >= 0)
@patch('stem.util.proc.is_available', Mock(return_value = False))
- def test_get_start_time_ps(self):
+ def test_start_time_ps(self):
"""
- Tests the get_start_time function with a ps response.
+ Tests the start_time function with a ps response.
"""
if not stem.util.system.is_available('ps'):
@@ -492,16 +492,16 @@ class TestSystem(unittest.TestCase):
return
pid = test.runner.get_runner().get_pid()
- self.assertTrue(stem.util.system.get_start_time(pid) >= 0)
+ self.assertTrue(stem.util.system.start_time(pid) >= 0)
- def test_get_bsd_jail_id(self):
+ def test_bsd_jail_id(self):
"""
- Exercises the stem.util.system.get_bsd_jail_id function, running through
+ Exercises the stem.util.system.bsd_jail_id function, running through
the failure case (since I'm not on BSD I can't really test this function
properly).
"""
- self.assertEquals(0, stem.util.system.get_bsd_jail_id(99999))
+ self.assertEquals(0, stem.util.system.bsd_jail_id(99999))
def test_expand_path(self):
"""
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index bc6711b..dd61feb 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -329,8 +329,8 @@ class TestControl(unittest.TestCase):
self.assertEqual('atagar', self.controller.get_user())
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
- @patch('stem.util.system.get_pid_by_name', Mock(return_value = 432))
- @patch('stem.util.system.get_user', Mock(return_value = 'atagar'))
+ @patch('stem.util.system.pid_by_name', Mock(return_value = 432))
+ @patch('stem.util.system.user', Mock(return_value = 'atagar'))
def test_get_user_by_system(self):
"""
Exercise the get_user() resolution via the system module.
@@ -371,7 +371,7 @@ class TestControl(unittest.TestCase):
open_mock.assert_called_once_with('/tmp/pid_file')
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
- @patch('stem.util.system.get_pid_by_name', Mock(return_value = 432))
+ @patch('stem.util.system.pid_by_name', Mock(return_value = 432))
def test_get_pid_by_name(self):
"""
Exercise the get_pid() resolution via the process name.
diff --git a/test/unit/response/protocolinfo.py b/test/unit/response/protocolinfo.py
index 15c7f97..fa87a0d 100644
--- a/test/unit/response/protocolinfo.py
+++ b/test/unit/response/protocolinfo.py
@@ -176,7 +176,7 @@ class TestProtocolInfoResponse(unittest.TestCase):
control_message = mocking.get_message(RELATIVE_COOKIE_PATH)
stem.response.convert('PROTOCOLINFO', control_message)
- stem.connection._expand_cookie_path(control_message, stem.util.system.get_pid_by_name, 'tor')
+ stem.connection._expand_cookie_path(control_message, stem.util.system.pid_by_name, 'tor')
self.assertEquals(os.path.join('/tmp/foo', 'tor-browser_en-US', 'Data', 'control_auth_cookie'), control_message.cookie_path)
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index dc1a9eb..f44a851 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -145,7 +145,7 @@ class TestConnection(unittest.TestCase):
self.assertEqual('BitTorrent', stem.util.connection.port_usage(6999))
self.assertEqual(None, stem.util.connection.port_usage(30000)) # unrecognized port
- @patch('stem.util.proc.get_connections')
+ @patch('stem.util.proc.connections')
def test_get_connections_by_proc(self, proc_mock):
"""
Checks the get_connections function with the proc resolver.
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index 7324c2b..911f151 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -18,7 +18,7 @@ try:
except ImportError:
from mock import Mock, patch
-# Base responses for the get_pid_by_name tests. The 'success' and
+# Base responses for the pid_by_name tests. The 'success' and
# 'multiple_results' entries are filled in by tests.
GET_PID_BY_NAME_BASE_RESULTS = {
@@ -138,9 +138,9 @@ class TestSystem(unittest.TestCase):
@patch('stem.util.system.call')
@patch('stem.util.proc.is_available', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_name_by_pid_ps(self, call_mock):
+ def test_name_by_pid_ps(self, call_mock):
"""
- Tests the get_name_by_pid function with ps responses.
+ Tests the name_by_pid function with ps responses.
"""
responses = {
@@ -156,13 +156,13 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 'vim' if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_name_by_pid(test_input))
+ self.assertEquals(expected_response, system.name_by_pid(test_input))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_pgrep(self, call_mock):
+ def test_pid_by_name_pgrep(self, call_mock):
"""
- Tests the get_pid_by_name function with pgrep responses.
+ Tests the pid_by_name function with pgrep responses.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -172,15 +172,15 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_pidof(self, call_mock):
+ def test_pid_by_name_pidof(self, call_mock):
"""
- Tests the get_pid_by_name function with pidof responses.
+ Tests the pid_by_name function with pidof responses.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -190,16 +190,16 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_bsd', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_ps_linux(self, call_mock):
+ def test_pid_by_name_ps_linux(self, call_mock):
"""
- Tests the get_pid_by_name function with the linux variant of ps.
+ Tests the pid_by_name function with the linux variant of ps.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -209,32 +209,32 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_bsd', Mock(return_value = True))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_ps_bsd(self, call_mock):
+ def test_pid_by_name_ps_bsd(self, call_mock):
"""
- Tests the get_pid_by_name function with the bsd variant of ps.
+ Tests the pid_by_name function with the bsd variant of ps.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD)
- self.assertEquals(1, system.get_pid_by_name('launchd'))
- self.assertEquals(11, system.get_pid_by_name('DirectoryService'))
- self.assertEquals(None, system.get_pid_by_name('blarg'))
+ self.assertEquals(1, system.pid_by_name('launchd'))
+ self.assertEquals(11, system.pid_by_name('DirectoryService'))
+ self.assertEquals(None, system.pid_by_name('blarg'))
call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD_MULTIPLE)
- self.assertEquals([1, 41], system.get_pid_by_name('launchd', multiple = True))
+ self.assertEquals([1, 41], system.pid_by_name('launchd', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_lsof(self, call_mock):
+ def test_pid_by_name_lsof(self, call_mock):
"""
- Tests the get_pid_by_name function with lsof responses.
+ Tests the pid_by_name function with lsof responses.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -244,69 +244,69 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_port_netstat(self, call_mock):
+ def test_pid_by_port_netstat(self, call_mock):
"""
- Tests the get_pid_by_port function with a netstat response.
+ Tests the pid_by_port function with a netstat response.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_NETSTAT, GET_PID_BY_PORT_NETSTAT_RESULTS)
- self.assertEquals(1641, system.get_pid_by_port(9051))
- self.assertEquals(1641, system.get_pid_by_port('9051'))
- self.assertEquals(None, system.get_pid_by_port(631))
- self.assertEquals(None, system.get_pid_by_port(123))
+ self.assertEquals(1641, system.pid_by_port(9051))
+ self.assertEquals(1641, system.pid_by_port('9051'))
+ self.assertEquals(None, system.pid_by_port(631))
+ self.assertEquals(None, system.pid_by_port(123))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_port_sockstat(self, call_mock):
+ def test_pid_by_port_sockstat(self, call_mock):
"""
- Tests the get_pid_by_port function with a sockstat response.
+ Tests the pid_by_port function with a sockstat response.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_SOCKSTAT % 9051, GET_PID_BY_PORT_SOCKSTAT_RESULTS)
- self.assertEquals(4397, system.get_pid_by_port(9051))
- self.assertEquals(4397, system.get_pid_by_port('9051'))
- self.assertEquals(None, system.get_pid_by_port(123))
+ self.assertEquals(4397, system.pid_by_port(9051))
+ self.assertEquals(4397, system.pid_by_port('9051'))
+ self.assertEquals(None, system.pid_by_port(123))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_port_lsof(self, call_mock):
+ def test_pid_by_port_lsof(self, call_mock):
"""
- Tests the get_pid_by_port function with a lsof response.
+ Tests the pid_by_port function with a lsof response.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_LSOF, GET_PID_BY_PORT_LSOF_RESULTS)
- self.assertEquals(1745, system.get_pid_by_port(9051))
- self.assertEquals(1745, system.get_pid_by_port('9051'))
- self.assertEquals(329, system.get_pid_by_port(80))
- self.assertEquals(None, system.get_pid_by_port(123))
+ self.assertEquals(1745, system.pid_by_port(9051))
+ self.assertEquals(1745, system.pid_by_port('9051'))
+ self.assertEquals(329, system.pid_by_port(80))
+ self.assertEquals(None, system.pid_by_port(123))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_open_file_lsof(self, call_mock):
+ def test_pid_by_open_file_lsof(self, call_mock):
"""
- Tests the get_pid_by_open_file function with a lsof response.
+ Tests the pid_by_open_file function with a lsof response.
"""
lsof_query = system.GET_PID_BY_FILE_LSOF % '/tmp/foo'
call_mock.side_effect = mock_call(lsof_query, ['4762'])
- self.assertEquals(4762, system.get_pid_by_open_file('/tmp/foo'))
+ self.assertEquals(4762, system.pid_by_open_file('/tmp/foo'))
call_mock.return_value = []
call_mock.side_effect = None
- self.assertEquals(None, system.get_pid_by_open_file('/tmp/somewhere_else'))
+ self.assertEquals(None, system.pid_by_open_file('/tmp/somewhere_else'))
@patch('stem.util.system.call')
@patch('stem.util.proc.is_available', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_cwd_pwdx(self, call_mock):
+ def test_cwd_pwdx(self, call_mock):
"""
- Tests the get_cwd function with a pwdx response.
+ Tests the cwd function with a pwdx response.
"""
responses = {
@@ -320,14 +320,14 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = '/home/atagar' if test_input == '3799' else None
- self.assertEquals(expected_response, system.get_cwd(test_input))
+ self.assertEquals(expected_response, system.cwd(test_input))
@patch('stem.util.system.call')
@patch('stem.util.proc.is_available', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_cwd_lsof(self, call_mock):
+ def test_cwd_lsof(self, call_mock):
"""
- Tests the get_cwd function with a lsof response.
+ Tests the cwd function with a lsof response.
"""
responses = {
@@ -340,13 +340,13 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = '/Users/atagar/tor/src/or' if test_input == '75717' else None
- self.assertEquals(expected_response, system.get_cwd(test_input))
+ self.assertEquals(expected_response, system.cwd(test_input))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_bsd_jail_id(self, call_mock):
+ def test_bsd_jail_id(self, call_mock):
"""
- Tests the get_bsd_jail_id function.
+ Tests the bsd_jail_id function.
"""
responses = {
@@ -362,22 +362,22 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1 if test_input == '1111' else 0
- self.assertEquals(expected_response, system.get_bsd_jail_id(test_input))
+ self.assertEquals(expected_response, system.bsd_jail_id(test_input))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_bsd_jail_path(self, call_mock):
+ def test_bsd_jail_path(self, call_mock):
"""
- Tests the get_bsd_jail_path function.
+ Tests the bsd_jail_path function.
"""
# check when we don't have a jail
call_mock.return_value = []
- self.assertEquals(None, system.get_bsd_jail_path(1))
+ self.assertEquals(None, system.bsd_jail_path(1))
call_mock.side_effect = mock_call(system.GET_BSD_JAIL_PATH % '1', GET_BSD_JAIL_PATH_RESULTS)
- self.assertEquals('/usr/jails/tor-jail', system.get_bsd_jail_path(1))
+ self.assertEquals('/usr/jails/tor-jail', system.bsd_jail_path(1))
@patch('platform.system', Mock(return_value = 'Linux'))
@patch('os.path.join', Mock(side_effect = posixpath.join))
1
0

02 Sep '14
commit 886b8e564aa9d4795ca915949a1004106efa4be0
Merge: 20d7f9d 611ecdb
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 20:50:07 2014 -0700
Dropping get_* prefix from most util functions
Bad habbit from my java days. The get_* prefix for these function names didn't
add anything, they were just bloat. The old function names are aliases for the
new ones so no worries about backward compatability.
docs/change_log.rst | 10 +-
docs/tutorials/east_of_the_sun.rst | 8 +-
docs/tutorials/mirror_mirror_on_the_wall.rst | 2 +-
docs/tutorials/tortoise_and_the_hare.rst | 4 +-
run_tests.py | 4 +-
stem/connection.py | 14 +--
stem/control.py | 9 +-
stem/util/connection.py | 20 +++-
stem/util/proc.py | 53 ++++++----
stem/util/str_tools.py | 48 +++++----
stem/util/system.py | 66 +++++++-----
stem/util/test_tools.py | 25 ++++-
test/integ/util/connection.py | 4 +-
test/integ/util/proc.py | 32 +++---
test/integ/util/system.py | 142 +++++++++++++-------------
test/unit/control/controller.py | 6 +-
test/unit/doctest.py | 8 +-
test/unit/response/protocolinfo.py | 2 +-
test/unit/tutorial.py | 2 +-
test/unit/util/connection.py | 22 ++--
test/unit/util/proc.py | 64 ++++++------
test/unit/util/str_tools.py | 82 +++++++--------
test/unit/util/system.py | 120 +++++++++++-----------
23 files changed, 410 insertions(+), 337 deletions(-)
1
0

02 Sep '14
commit 7fc393595e9ee2e13283886df609402e9ed9bbfa
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 20:33:30 2014 -0700
Dropping get_* prefix from string util functions
---
docs/tutorials/mirror_mirror_on_the_wall.rst | 2 +-
docs/tutorials/tortoise_and_the_hare.rst | 4 +-
stem/util/str_tools.py | 48 +++++++++------
test/unit/doctest.py | 8 +--
test/unit/tutorial.py | 2 +-
test/unit/util/str_tools.py | 82 +++++++++++++-------------
6 files changed, 79 insertions(+), 67 deletions(-)
diff --git a/docs/tutorials/mirror_mirror_on_the_wall.rst b/docs/tutorials/mirror_mirror_on_the_wall.rst
index 0db54c3..8fc196b 100644
--- a/docs/tutorials/mirror_mirror_on_the_wall.rst
+++ b/docs/tutorials/mirror_mirror_on_the_wall.rst
@@ -186,7 +186,7 @@ could use any of the methods above, but for this example we'll use
for bw_value in sorted(bw_to_relay.keys(), reverse = True):
for nickname in bw_to_relay[bw_value]:
- print "%i. %s (%s/s)" % (count, nickname, str_tools.get_size_label(bw_value, 2))
+ print "%i. %s (%s/s)" % (count, nickname, str_tools.size_label(bw_value, 2))
count += 1
if count > 15:
diff --git a/docs/tutorials/tortoise_and_the_hare.rst b/docs/tutorials/tortoise_and_the_hare.rst
index a458e0d..d3f759e 100644
--- a/docs/tutorials/tortoise_and_the_hare.rst
+++ b/docs/tutorials/tortoise_and_the_hare.rst
@@ -107,10 +107,10 @@ uploaded.
# show the latest values at the top
- label = "Downloaded (%s/s):" % str_tools.get_size_label(download_rates[0], 1)
+ label = "Downloaded (%s/s):" % str_tools.size_label(download_rates[0], 1)
window.addstr(0, 1, label, DOWNLOAD_COLOR, curses.A_BOLD)
- label = "Uploaded (%s/s):" % str_tools.get_size_label(upload_rates[0], 1)
+ label = "Uploaded (%s/s):" % str_tools.size_label(upload_rates[0], 1)
window.addstr(0, GRAPH_WIDTH + 7, label, UPLOAD_COLOR, curses.A_BOLD)
# draw the graph bounds in KB
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index e166a4c..4bba8e3 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -4,16 +4,19 @@
"""
Toolkit for various string activity.
+**Note:** Many functions were previously named with a get_* prefix. Those names
+are now aliases, and will be dropped in Stem version 2.0.0.
+
**Module Overview:**
::
crop - shortens string to a given length
- get_size_label - human readable label for a number of bytes
- get_time_label - human readable label for a number of seconds
- get_time_labels - human readable labels for each time unit
- get_short_time_label - condensed time label output
+ size_label - human readable label for a number of bytes
+ time_label - human readable label for a number of seconds
+ time_labels - human readable labels for each time unit
+ short_time_label - condensed time label output
parse_short_time_label - seconds represented by a short time label
"""
@@ -251,7 +254,7 @@ def crop(msg, size, min_word_length = 4, min_crop = 0, ending = Ending.ELLIPSE,
return (return_msg, remainder) if get_remainder else return_msg
-def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
+def size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
"""
Converts a number of bytes into a human readable label in its most
significant units. For instance, 7500 bytes would return "7 KB". If the
@@ -261,13 +264,13 @@ def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
::
- >>> get_size_label(2000000)
+ >>> size_label(2000000)
'1 MB'
- >>> get_size_label(1050, 2)
+ >>> size_label(1050, 2)
'1.02 KB'
- >>> get_size_label(1050, 3, True)
+ >>> size_label(1050, 3, True)
'1.025 Kilobytes'
:param int byte_count: number of bytes to be converted
@@ -284,7 +287,7 @@ def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
return _get_label(SIZE_UNITS_BITS, byte_count, decimal, is_long)
-def get_time_label(seconds, decimal = 0, is_long = False):
+def time_label(seconds, decimal = 0, is_long = False):
"""
Converts seconds into a time label truncated to its most significant units.
For instance, 7500 seconds would return "2h". Units go up through days.
@@ -296,13 +299,13 @@ def get_time_label(seconds, decimal = 0, is_long = False):
::
- >>> get_time_label(10000)
+ >>> time_label(10000)
'2h'
- >>> get_time_label(61, 1, True)
+ >>> time_label(61, 1, True)
'1.0 minute'
- >>> get_time_label(61, 2, True)
+ >>> time_label(61, 2, True)
'1.01 minutes'
:param int seconds: number of seconds to be converted
@@ -315,7 +318,7 @@ def get_time_label(seconds, decimal = 0, is_long = False):
return _get_label(TIME_UNITS, seconds, decimal, is_long)
-def get_time_labels(seconds, is_long = False):
+def time_labels(seconds, is_long = False):
"""
Provides a list of label conversions for each time unit, starting with its
most significant units on down. Any counts that evaluate to zero are omitted.
@@ -323,10 +326,10 @@ def get_time_labels(seconds, is_long = False):
::
- >>> get_time_labels(400)
+ >>> time_labels(400)
['6m', '40s']
- >>> get_time_labels(3640, True)
+ >>> time_labels(3640, True)
['1 hour', '40 seconds']
:param int seconds: number of seconds to be converted
@@ -345,17 +348,17 @@ def get_time_labels(seconds, is_long = False):
return time_labels
-def get_short_time_label(seconds):
+def short_time_label(seconds):
"""
Provides a time in the following format:
[[dd-]hh:]mm:ss
::
- >>> get_short_time_label(111)
+ >>> short_time_label(111)
'01:51'
- >>> get_short_time_label(544100)
+ >>> short_time_label(544100)
'6-07:08:20'
:param int seconds: number of seconds to be converted
@@ -505,3 +508,12 @@ def _get_label(units, count, decimal, is_long):
return count_label + long_label + ('s' if is_plural else '')
else:
return count_label + short_label
+
+# TODO: drop with stem 2.x
+# We renamed our methods to drop a redundant 'get_*' prefix, so alias the old
+# names for backward compatability.
+
+get_size_label = size_label
+get_time_label = time_label
+get_time_labels = time_labels
+get_short_time_label = short_time_label
diff --git a/test/unit/doctest.py b/test/unit/doctest.py
index 1c7c415..e3e53d8 100644
--- a/test/unit/doctest.py
+++ b/test/unit/doctest.py
@@ -60,10 +60,10 @@ class TestDocumentation(unittest.TestCase):
args['globs'] = {
'_to_camel_case': stem.util.str_tools._to_camel_case,
'crop': stem.util.str_tools.crop,
- 'get_size_label': stem.util.str_tools.get_size_label,
- 'get_time_label': stem.util.str_tools.get_time_label,
- 'get_time_labels': stem.util.str_tools.get_time_labels,
- 'get_short_time_label': stem.util.str_tools.get_short_time_label,
+ 'size_label': stem.util.str_tools.size_label,
+ 'time_label': stem.util.str_tools.time_label,
+ 'time_labels': stem.util.str_tools.time_labels,
+ 'short_time_label': stem.util.str_tools.short_time_label,
'parse_short_time_label': stem.util.str_tools.parse_short_time_label,
}
diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py
index 1c853c0..1ee6396 100644
--- a/test/unit/tutorial.py
+++ b/test/unit/tutorial.py
@@ -151,7 +151,7 @@ class TestTutorial(unittest.TestCase):
for bw_value in sorted(bw_to_relay.keys(), reverse = True):
for nickname in bw_to_relay[bw_value]:
- print '%i. %s (%s/s)' % (count, nickname, str_tools.get_size_label(bw_value, 2))
+ print '%i. %s (%s/s)' % (count, nickname, str_tools.size_label(bw_value, 2))
count += 1
if count > 15:
diff --git a/test/unit/util/str_tools.py b/test/unit/util/str_tools.py
index 7abdedf..f874be6 100644
--- a/test/unit/util/str_tools.py
+++ b/test/unit/util/str_tools.py
@@ -31,76 +31,76 @@ class TestStrTools(unittest.TestCase):
self.assertEquals('This is a...', str_tools.crop('This is a looooong message', 12))
self.assertEquals('', str_tools.crop('This is a looooong message', 3))
- def test_get_size_label(self):
+ def test_size_label(self):
"""
- Checks the get_size_label() function.
+ Checks the size_label() function.
"""
# test the pydoc examples
- self.assertEquals('1 MB', str_tools.get_size_label(2000000))
- self.assertEquals('1.02 KB', str_tools.get_size_label(1050, 2))
- self.assertEquals('1.025 Kilobytes', str_tools.get_size_label(1050, 3, True))
+ self.assertEquals('1 MB', str_tools.size_label(2000000))
+ self.assertEquals('1.02 KB', str_tools.size_label(1050, 2))
+ self.assertEquals('1.025 Kilobytes', str_tools.size_label(1050, 3, True))
- self.assertEquals('0 B', str_tools.get_size_label(0))
- self.assertEquals('0 Bytes', str_tools.get_size_label(0, is_long = True))
- self.assertEquals('0.00 B', str_tools.get_size_label(0, 2))
- self.assertEquals('-10 B', str_tools.get_size_label(-10))
- self.assertEquals('80 b', str_tools.get_size_label(10, is_bytes = False))
- self.assertEquals('-1 MB', str_tools.get_size_label(-2000000))
+ self.assertEquals('0 B', str_tools.size_label(0))
+ self.assertEquals('0 Bytes', str_tools.size_label(0, is_long = True))
+ self.assertEquals('0.00 B', str_tools.size_label(0, 2))
+ self.assertEquals('-10 B', str_tools.size_label(-10))
+ self.assertEquals('80 b', str_tools.size_label(10, is_bytes = False))
+ self.assertEquals('-1 MB', str_tools.size_label(-2000000))
# checking that we round down
- self.assertEquals('23.43 Kb', str_tools.get_size_label(3000, 2, is_bytes = False))
+ self.assertEquals('23.43 Kb', str_tools.size_label(3000, 2, is_bytes = False))
- self.assertRaises(TypeError, str_tools.get_size_label, None)
- self.assertRaises(TypeError, str_tools.get_size_label, 'hello world')
+ self.assertRaises(TypeError, str_tools.size_label, None)
+ self.assertRaises(TypeError, str_tools.size_label, 'hello world')
- def test_get_time_label(self):
+ def test_time_label(self):
"""
- Checks the get_time_label() function.
+ Checks the time_label() function.
"""
# test the pydoc examples
- self.assertEquals('2h', str_tools.get_time_label(10000))
- self.assertEquals('1.0 minute', str_tools.get_time_label(61, 1, True))
- self.assertEquals('1.01 minutes', str_tools.get_time_label(61, 2, True))
+ self.assertEquals('2h', str_tools.time_label(10000))
+ self.assertEquals('1.0 minute', str_tools.time_label(61, 1, True))
+ self.assertEquals('1.01 minutes', str_tools.time_label(61, 2, True))
- self.assertEquals('0s', str_tools.get_time_label(0))
- self.assertEquals('0 seconds', str_tools.get_time_label(0, is_long = True))
- self.assertEquals('0.00s', str_tools.get_time_label(0, 2))
- self.assertEquals('-10s', str_tools.get_time_label(-10))
+ self.assertEquals('0s', str_tools.time_label(0))
+ self.assertEquals('0 seconds', str_tools.time_label(0, is_long = True))
+ self.assertEquals('0.00s', str_tools.time_label(0, 2))
+ self.assertEquals('-10s', str_tools.time_label(-10))
- self.assertRaises(TypeError, str_tools.get_time_label, None)
- self.assertRaises(TypeError, str_tools.get_time_label, 'hello world')
+ self.assertRaises(TypeError, str_tools.time_label, None)
+ self.assertRaises(TypeError, str_tools.time_label, 'hello world')
- def test_get_time_labels(self):
+ def test_time_labels(self):
"""
- Checks the get_time_labels() function.
+ Checks the time_labels() function.
"""
# test the pydoc examples
- self.assertEquals(['6m', '40s'], str_tools.get_time_labels(400))
- self.assertEquals(['1 hour', '40 seconds'], str_tools.get_time_labels(3640, True))
+ self.assertEquals(['6m', '40s'], str_tools.time_labels(400))
+ self.assertEquals(['1 hour', '40 seconds'], str_tools.time_labels(3640, True))
- self.assertEquals([], str_tools.get_time_labels(0))
- self.assertEquals(['-10s'], str_tools.get_time_labels(-10))
+ self.assertEquals([], str_tools.time_labels(0))
+ self.assertEquals(['-10s'], str_tools.time_labels(-10))
- self.assertRaises(TypeError, str_tools.get_time_labels, None)
- self.assertRaises(TypeError, str_tools.get_time_labels, 'hello world')
+ self.assertRaises(TypeError, str_tools.time_labels, None)
+ self.assertRaises(TypeError, str_tools.time_labels, 'hello world')
- def test_get_short_time_label(self):
+ def test_short_time_label(self):
"""
- Checks the get_short_time_label() function.
+ Checks the short_time_label() function.
"""
# test the pydoc examples
- self.assertEquals('01:51', str_tools.get_short_time_label(111))
- self.assertEquals('6-07:08:20', str_tools.get_short_time_label(544100))
+ self.assertEquals('01:51', str_tools.short_time_label(111))
+ self.assertEquals('6-07:08:20', str_tools.short_time_label(544100))
- self.assertEquals('00:00', str_tools.get_short_time_label(0))
+ self.assertEquals('00:00', str_tools.short_time_label(0))
- self.assertRaises(TypeError, str_tools.get_short_time_label, None)
- self.assertRaises(TypeError, str_tools.get_short_time_label, 'hello world')
- self.assertRaises(ValueError, str_tools.get_short_time_label, -5)
+ self.assertRaises(TypeError, str_tools.short_time_label, None)
+ self.assertRaises(TypeError, str_tools.short_time_label, 'hello world')
+ self.assertRaises(ValueError, str_tools.short_time_label, -5)
def test_parse_short_time_label(self):
"""
1
0

02 Sep '14
commit 611ecdbcaea03d28564dcce5129366e9e90d4813
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Sep 1 20:41:05 2014 -0700
Dropping get_* prefix from testing functions
---
run_tests.py | 4 ++--
stem/util/test_tools.py | 25 ++++++++++++++++++++-----
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index 2d73457..2a541cf 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -91,7 +91,7 @@ https://pypi.python.org/pypi/mock/
PYFLAKES_TASK = Task(
"running pyflakes",
- stem.util.test_tools.get_pyflakes_issues,
+ stem.util.test_tools.pyflakes_issues,
args = (SRC_PATHS,),
is_required = False,
print_result = False,
@@ -99,7 +99,7 @@ PYFLAKES_TASK = Task(
PEP8_TASK = Task(
"running pep8",
- stem.util.test_tools.get_stylistic_issues,
+ stem.util.test_tools.stylistic_issues,
args = (SRC_PATHS, True, True, True, True),
is_required = False,
print_result = False,
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py
index ba6392d..8209c58 100644
--- a/stem/util/test_tools.py
+++ b/stem/util/test_tools.py
@@ -13,8 +13,8 @@ Helper functions for testing.
is_pyflakes_available - checks if pyflakes is available
is_pep8_available - checks if pep8 is available
- get_stylistic_issues - checks for PEP8 and other stylistic issues
- get_pyflakes_issues - static checks for problems via pyflakes
+ stylistic_issues - checks for PEP8 and other stylistic issues
+ pyflakes_issues - static checks for problems via pyflakes
"""
import os
@@ -103,7 +103,7 @@ def is_pep8_available():
return False
-def get_stylistic_issues(paths, check_two_space_indents = False, check_newlines = False, check_trailing_whitespace = False, check_exception_keyword = False):
+def stylistic_issues(paths, check_two_space_indents = False, check_newlines = False, check_trailing_whitespace = False, check_exception_keyword = False):
"""
Checks for stylistic issues that are an issue according to the parts of PEP8
we conform to. You can suppress PEP8 issues by making a 'test' configuration
@@ -131,11 +131,15 @@ def get_stylistic_issues(paths, check_two_space_indents = False, check_newlines
test_config = stem.util.conf.get_config('test')
test_config.load('test/settings.cfg')
- issues = get_stylistic_issues('my_project')
+ issues = stylistic_issues('my_project')
If a 'exclude_paths' was set in our test config then we exclude any absolute
paths matching those regexes.
+ .. versionchanged:: 1.3.0
+ Renamed from get_stylistic_issues() to stylistic_issues(). The old name
+ still works as an alias, but will be dropped in Stem version 2.0.0.
+
:param list paths: paths to search for stylistic issues
:param bool check_two_space_indents: check for two space indentations and
that no tabs snuck in
@@ -209,7 +213,7 @@ def get_stylistic_issues(paths, check_two_space_indents = False, check_newlines
return issues
-def get_pyflakes_issues(paths):
+def pyflakes_issues(paths):
"""
Performs static checks via pyflakes. False positives can be ignored via
'pyflakes.ignore' entries in our 'test' config. For instance...
@@ -222,6 +226,10 @@ def get_pyflakes_issues(paths):
If a 'exclude_paths' was set in our test config then we exclude any absolute
paths matching those regexes.
+ .. versionchanged:: 1.3.0
+ Renamed from get_pyflakes_issues() to pyflakes_issues(). The old name
+ still works as an alias, but will be dropped in Stem version 2.0.0.
+
:param list paths: paths to search for problems
:returns: dict of the form ``path => [(line_number, message)...]``
@@ -284,3 +292,10 @@ def _python_files(paths):
if not skip:
yield file_path
+
+# TODO: drop with stem 2.x
+# We renamed our methods to drop a redundant 'get_*' prefix, so alias the old
+# names for backward compatability.
+
+get_stylistic_issues = stylistic_issues
+get_pyflakes_issues = pyflakes_issues
1
0