|
1
|
|
|
import platform |
|
2
|
|
|
import subprocess |
|
3
|
|
|
import os |
|
4
|
|
|
from rsudp import COLOR, log_loc, settings_loc |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
def ep_edit_settings(): |
|
8
|
|
|
''' |
|
9
|
|
|
.. versionadded:: 1.0.3 |
|
10
|
|
|
|
|
11
|
|
|
This function calls the system's default text editor to open the settings |
|
12
|
|
|
file for editing. It is provided for convenience only. |
|
13
|
|
|
Advanced users may prefer to add an alias in place of this function. |
|
14
|
|
|
The alias **should** override the entrypoint command set in rsudp's |
|
15
|
|
|
``setup.py``. |
|
16
|
|
|
|
|
17
|
|
|
On Linux and MacOS, adding an alias may look like this: |
|
18
|
|
|
|
|
19
|
|
|
.. code-block:: bash |
|
20
|
|
|
|
|
21
|
|
|
# add the alias definition to the aliases file |
|
22
|
|
|
echo "alias rsudp-settings='nano ~/.config/rsudp/rsudp_settings.json'" >> .bash_aliases |
|
23
|
|
|
# then reload the console |
|
24
|
|
|
bash |
|
25
|
|
|
|
|
26
|
|
|
To add an alias on Windows via the command prompt is much more difficult. |
|
27
|
|
|
|
|
28
|
|
|
.. note:: |
|
29
|
|
|
|
|
30
|
|
|
This function has been tested on multiple operating systems, but |
|
31
|
|
|
because each system's functionality and defaults may be different, |
|
32
|
|
|
proper operation cannot be not guaranteed. |
|
33
|
|
|
|
|
34
|
|
|
''' |
|
35
|
|
|
if not os.path.exists(settings_loc): |
|
36
|
|
|
raise(FileNotFoundError('Settings file not found at %s' % settings_loc)) |
|
37
|
|
|
|
|
38
|
|
|
if platform.system() == 'Darwin': # MacOS |
|
39
|
|
|
subprocess.call(('open', settings_loc)) |
|
40
|
|
|
elif platform.system() == 'Windows': # Windows |
|
41
|
|
|
os.startfile(settings_loc) |
|
42
|
|
|
else: # linux variants |
|
43
|
|
|
subprocess.call(('xdg-open', settings_loc)) |
|
44
|
|
|
|
|
45
|
|
|
def ep_cat_log(): |
|
46
|
|
|
''' |
|
47
|
|
|
.. versionadded:: 1.0.3 |
|
48
|
|
|
|
|
49
|
|
|
This function uses a posix system's ``cat`` command to print messages in |
|
50
|
|
|
the rsudp log file. It is provided for convenience only. |
|
51
|
|
|
|
|
52
|
|
|
It is accessible via the console command ``rs-log`` on posix (Linux, MacOS) |
|
53
|
|
|
style operating systems. |
|
54
|
|
|
''' |
|
55
|
|
|
if os.name == 'posix': |
|
56
|
|
|
subprocess.call(('cat', log_loc)) |
|
57
|
|
|
else: |
|
58
|
|
|
printE('This command is only available on posix (Linux, MacOS) machines.') |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
def ep_tailf_log(): |
|
61
|
|
|
''' |
|
62
|
|
|
.. versionadded:: 1.0.3 |
|
63
|
|
|
|
|
64
|
|
|
This function uses a the system's follow command to follow new |
|
65
|
|
|
messages added to the log file. It is provided for convenience only. |
|
66
|
|
|
is the equivalent of ``tail -f /tmp/rsudp/rsudp.log`` on Linux/MacOS |
|
67
|
|
|
and ``Get-Content -Path "C:/tmp/rsudp/rsudp.log" -Wait`` on Windows. |
|
68
|
|
|
|
|
69
|
|
|
It is accessible via the console command ``rs-tailf``. |
|
70
|
|
|
|
|
71
|
|
|
The function will run until it receives a keyboard interrupt (CTRL+C). |
|
72
|
|
|
''' |
|
73
|
|
|
if os.name == 'posix': |
|
74
|
|
|
try: |
|
75
|
|
|
print(COLOR['blue'] + 'Entering log follow (tail -f) mode.') |
|
76
|
|
|
print('New log messages will be printed until the console receives an interrupt (CTRL+C to end).' + COLOR['white']) |
|
77
|
|
|
subprocess.call(('tail','-f', log_loc)) |
|
78
|
|
|
except KeyboardInterrupt: |
|
79
|
|
|
print() |
|
80
|
|
|
print(COLOR['blue'] + 'Quitting tail -f mode.' + COLOR['white']) |
|
81
|
|
|
if os.name == 'nt': |
|
82
|
|
|
try: |
|
83
|
|
|
print('Entering log follow mode.') |
|
84
|
|
|
print('New log messages will be printed until the console receives an interrupt (CTRL+C to end).') |
|
85
|
|
|
subprocess.call(('Get-Content', '-Path', '"C:/tmp/rsudp/rsudp.log"', '-Wait')) |
|
86
|
|
|
except Exception as e: |
|
87
|
|
|
print('This function is not available on Windows. Error: %s' % (e)) |
|
88
|
|
|
|