diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2023-01-30 12:20:23 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2023-01-30 12:20:23 +0100 |
commit | cfc871cce6aefaa0ff64619780a807cba761c6b2 (patch) | |
tree | 965e8276ed36f11698b6c7d6eadab9f88d5f97c5 /tools/tai64dec | |
parent | aa54fe89b98d354d21141c589332ce7950ef2e59 (diff) | |
download | nixos-cfc871cce6aefaa0ff64619780a807cba761c6b2.tar nixos-cfc871cce6aefaa0ff64619780a807cba761c6b2.tar.gz nixos-cfc871cce6aefaa0ff64619780a807cba761c6b2.tar.bz2 nixos-cfc871cce6aefaa0ff64619780a807cba761c6b2.tar.xz nixos-cfc871cce6aefaa0ff64619780a807cba761c6b2.zip |
...
Diffstat (limited to 'tools/tai64dec')
-rw-r--r-- | tools/tai64dec/default.nix | 18 | ||||
-rw-r--r-- | tools/tai64dec/setup.py | 10 | ||||
-rw-r--r-- | tools/tai64dec/tai64dec/__main__.py | 46 |
3 files changed, 0 insertions, 74 deletions
diff --git a/tools/tai64dec/default.nix b/tools/tai64dec/default.nix deleted file mode 100644 index 380c22bf..00000000 --- a/tools/tai64dec/default.nix +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | { system, self, mach-nix, leapseconds, ... }: | ||
2 | let | ||
3 | pkgs = self.legacyPackages.${system}; | ||
4 | in mach-nix.lib.${system}.buildPythonPackage { | ||
5 | pname = "tai64dec"; | ||
6 | src = pkgs.lib.sourceByRegex ./. ["^setup\.py$" "^tai64dec(/[^/]+.*)?$"]; | ||
7 | version = "0.0.0"; | ||
8 | ignoreDataOutdated = true; | ||
9 | |||
10 | requirements = '' | ||
11 | leapseconddata | ||
12 | ''; | ||
13 | |||
14 | postInstall = '' | ||
15 | wrapProgram $out/bin/tai64dec \ | ||
16 | --set-default LEAPSECONDS_FILE ${leapseconds} | ||
17 | ''; | ||
18 | } | ||
diff --git a/tools/tai64dec/setup.py b/tools/tai64dec/setup.py deleted file mode 100644 index d936796b..00000000 --- a/tools/tai64dec/setup.py +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | from setuptools import setup | ||
2 | |||
3 | setup(name='tai64dec', | ||
4 | packages=['tai64dec'], | ||
5 | entry_points={ | ||
6 | 'console_scripts': [ | ||
7 | 'tai64dec=tai64dec.__main__:main' | ||
8 | ], | ||
9 | }, | ||
10 | ) | ||
diff --git a/tools/tai64dec/tai64dec/__main__.py b/tools/tai64dec/tai64dec/__main__.py deleted file mode 100644 index a8854523..00000000 --- a/tools/tai64dec/tai64dec/__main__.py +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | import sys, os | ||
2 | |||
3 | import argparse | ||
4 | |||
5 | from leapseconddata import LeapSecondData | ||
6 | from math import ldexp | ||
7 | from pathlib import Path | ||
8 | from datetime import datetime, timezone | ||
9 | import secrets | ||
10 | |||
11 | |||
12 | class BooleanAction(argparse.Action): | ||
13 | def __init__(self, option_strings, dest, nargs=None, **kwargs): | ||
14 | super(BooleanAction, self).__init__(option_strings, dest, nargs=0, **kwargs) | ||
15 | |||
16 | def __call__(self, parser, namespace, values, option_string=None): | ||
17 | setattr(namespace, self.dest, False if option_string.startswith('--no') else True) | ||
18 | |||
19 | |||
20 | def main(): | ||
21 | parser = argparse.ArgumentParser(prog='tai64dec', formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
22 | parser.add_argument('--random', '--no-random', action=BooleanAction, default=False) | ||
23 | parser.add_argument('--ns', '--no-ns', action=BooleanAction, default=True) | ||
24 | args = parser.parse_args() | ||
25 | |||
26 | |||
27 | leapsecond_data = LeapSecondData.from_file(Path(os.getenv('LEAPSECONDS_FILE'))) | ||
28 | |||
29 | now = datetime.now(tz=timezone.utc) | ||
30 | |||
31 | tai_dt = leapsecond_data.to_tai(now) | ||
32 | seconds = int(tai_dt.timestamp()) | ||
33 | seconds += int(ldexp(1, 62)) | ||
34 | out = seconds | ||
35 | |||
36 | if args.ns: | ||
37 | nanoseconds = int((tai_dt.timestamp() - seconds) / 1e-9) | ||
38 | out = out << 32 | nanoseconds | ||
39 | |||
40 | if args.random: | ||
41 | out = out << 24 | int.from_bytes(secrets.token_bytes(3), byteorder='little', signed=False) | ||
42 | |||
43 | print('{:d}'.format(out), file=sys.stdout) | ||
44 | |||
45 | if __name__ == '__main__': | ||
46 | sys.exit(main()) | ||