-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from networktocode/develop
1.1.0 release
- Loading branch information
Showing
70 changed files
with
53,220 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ Examples | |
######## | ||
|
||
.. mdinclude:: ../../../README.md | ||
:start-line: 50 | ||
:end-line: 102 | ||
:start-line: 53 | ||
:end-line: 105 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ Netutils Functions | |
ping/index | ||
protocol_mapper/index | ||
route/index | ||
time/index | ||
utilities/index | ||
vlan/index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
******* | ||
Time | ||
******* | ||
|
||
.. automodule:: netutils.time | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ Overview | |
|
||
.. mdinclude:: ../../../README.md | ||
:start-line: 0 | ||
:end-line: 33 | ||
:end-line: 36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Initialization file for library.""" | ||
|
||
__version__ = "1.0.0" | ||
__version__ = "1.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Functions for working with time.""" | ||
import re | ||
from .constants import TIME_MAPPINGS, UPTIME_REGEX_PATTERNS | ||
|
||
|
||
def uptime_seconds_to_string(uptime_seconds): | ||
"""Converts uptime in seconds to uptime in string format. | ||
Args: | ||
uptime_seconds (int): Uptime in seconds. | ||
Returns: | ||
str: Uptime in string format. | ||
Example: | ||
>>> from netutils.time import uptime_seconds_to_string | ||
>>> uptime_seconds_to_string(7250) | ||
'2 hours, 50 seconds' | ||
""" | ||
result = [] | ||
for interval, count in TIME_MAPPINGS: | ||
value = uptime_seconds // count | ||
if value: | ||
uptime_seconds -= value * count | ||
if value == 1: | ||
interval = interval.rstrip("s") | ||
result.append(f"{value} {interval}") | ||
|
||
return ", ".join(result) | ||
|
||
|
||
def uptime_string_to_seconds(uptime_string): | ||
"""Converts uptime string seconds. | ||
Args: | ||
uptime_string (str): Uptime in string format | ||
Returns: | ||
int: Uptime string converted to seconds. | ||
Example: | ||
>>> from netutils.time import uptime_string_to_seconds | ||
>>> uptime_string_to_seconds("58 minutes") | ||
3480 | ||
>>> from netutils.time import uptime_string_to_seconds | ||
>>> uptime_string_to_seconds("4m15s") | ||
255 | ||
Raises: | ||
ValueError: When uptime_string is unable to be parsed by regex. | ||
""" | ||
compiled_regex_list = [re.compile(reg_pattern) for reg_pattern in UPTIME_REGEX_PATTERNS] | ||
|
||
uptime_dict = {} | ||
for regex in compiled_regex_list: | ||
match = regex.search(uptime_string) | ||
|
||
if match: | ||
uptime_dict = match.groupdict() | ||
break | ||
|
||
if not match: | ||
raise ValueError("Unable to parse uptime string.") | ||
|
||
uptime_seconds = 0 | ||
for time_interval, value in TIME_MAPPINGS: | ||
if uptime_dict.get(time_interval): | ||
uptime_seconds += int(uptime_dict.get(time_interval)) * value | ||
return uptime_seconds |
Oops, something went wrong.