-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.py
64 lines (50 loc) · 2.14 KB
/
library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/local/python3
# This code was developed for MacOS but should work under Windows and Linux
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not,
# see <https://www.gnu.org/licenses/>.
# Having said that, it would be great to know if this software gets used. If you want, buy me a coffee, or send me some hardware
# Darryl Smith, VK2TDS. [email protected] Copyright 2023
import string
from datetime import datetime
def is_hex(s):
hex_digits = set(string.hexdigits)
# if s is long, then it is faster to check against a set
return all(c in hex_digits for c in s)
def to_user (command, old, new):
if old is None:
if new is True:
new = 'On'
if new is False:
new = 'Off'
return ('%s%s' % (command.ljust(13), str(new).ljust(10)))
else:
# old is NOT None
if new is True:
new = 'On'
if new is False:
new = 'Off'
if old is True:
old = 'On'
if old is False:
old = 'Off'
return ('%s was %s' % (command, old))
def displaydatetime (dt, completer):
if completer.options['DAYUSA'].Value:
if completer.options['AMONTH'].Value:
return dt.strftime ('%d-%b-%Y %H:%M:%S')
else:
return dt.strftime ('%m/%d/%Y %H:%M:%S')
else:
if completer.options['AMONTH'].Value:
return dt.strftime ('%d-%b-%Y %H:%M:%S')
else:
return dt.strftime ('%d/%m/%Y %H:%M:%S')
def datetimenow (completer):
if completer.options['UTC'].Value:
return datetime.utcnow()
else:
return datetime.now()