fundamentals 2.7.8__tar.gz → 2.8.1.dev0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/CHANGES.md +8 -0
- fundamentals-2.8.1.dev0/CITATION.cff +12 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/PKG-INFO +39 -15
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/README.md +3 -6
- fundamentals-2.8.1.dev0/fundamentals/__version__.py +1 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/cl_utils.py +25 -12
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/commonutils/__init__.py +1 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/commonutils/getpackagepath.py +4 -2
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/daemonise.py +45 -58
- fundamentals-2.8.1.dev0/fundamentals/docstring_test.py +245 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/download/__init__.py +1 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/download/_dump_files_to_local_drive.py +23 -13
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/download/_fetch.py +16 -11
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/download/append_now_datestamp_to_filename.py +16 -10
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/download/extract_filename_from_url.py +14 -10
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/download/get_now_datetime_filestamp.py +7 -4
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/download/multiobject_download.py +44 -30
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/files/__init__.py +1 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/files/fileChunker.py +13 -10
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/files/list_of_dictionaries_to_mysql_inserts.py +13 -13
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/files/recursive_directory_listing.py +18 -16
- fundamentals-2.8.1.dev0/fundamentals/files/resources/ratings/0.plist +6 -0
- fundamentals-2.8.1.dev0/fundamentals/files/resources/ratings/1.plist +0 -0
- fundamentals-2.8.1.dev0/fundamentals/files/resources/ratings/2.plist +0 -0
- fundamentals-2.8.1.dev0/fundamentals/files/resources/ratings/3.plist +0 -0
- fundamentals-2.8.1.dev0/fundamentals/files/resources/ratings/4.plist +0 -0
- fundamentals-2.8.1.dev0/fundamentals/files/resources/ratings/5.plist +0 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/files/tag.py +54 -46
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/fmultiprocess.py +39 -29
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/logs.py +70 -26
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/__init__.py +4 -1
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/convert_dictionary_to_mysql_table.py +219 -149
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/database.py +38 -42
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/directory_script_runner.py +102 -68
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/get_database_table_column_names.py +16 -17
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/insert_list_of_dictionaries_into_database_tables.py +107 -100
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/readquery.py +21 -16
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/setup_database_connection.py +31 -21
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/sqlite2mysql.py +77 -58
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/table_exists.py +14 -19
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/writequery.py +36 -35
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/mysql/yaml_to_database.py +43 -43
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/nose2_plugins/cprof.py +16 -16
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/renderer/__init__.py +1 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/renderer/list_of_dictionaries.py +112 -104
- fundamentals-2.8.1.dev0/fundamentals/resources/package.mplstyle +114 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/stats/__init__.py +1 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/stats/rolling_window_sigma_clip.py +25 -15
- fundamentals-2.8.1.dev0/fundamentals/test_settings.yaml +66 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/times.py +18 -14
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/tools.py +184 -106
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/utKit.py +24 -23
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals.egg-info/SOURCES.txt +11 -11
- fundamentals-2.8.1.dev0/pyproject.toml +92 -0
- fundamentals-2.8.1.dev0/setup.cfg +4 -0
- fundamentals-2.7.8/.readthedocs.yaml +0 -27
- fundamentals-2.7.8/MANIFEST.in +0 -17
- fundamentals-2.7.8/fundamentals/__version__.py +0 -1
- fundamentals-2.7.8/fundamentals.egg-info/PKG-INFO +0 -72
- fundamentals-2.7.8/fundamentals.egg-info/dependency_links.txt +0 -1
- fundamentals-2.7.8/fundamentals.egg-info/entry_points.txt +0 -4
- fundamentals-2.7.8/fundamentals.egg-info/not-zip-safe +0 -1
- fundamentals-2.7.8/fundamentals.egg-info/requires.txt +0 -9
- fundamentals-2.7.8/fundamentals.egg-info/top_level.txt +0 -1
- fundamentals-2.7.8/setup.cfg +0 -7
- fundamentals-2.7.8/setup.py +0 -65
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/LICENSE +0 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/__init__.py +0 -0
- {fundamentals-2.7.8 → fundamentals-2.8.1.dev0}/fundamentals/nose2_plugins/__init__.py +0 -0
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
## Release Notes
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
**v2.8.0 - May 20, 2026**
|
|
6
|
+
|
|
7
|
+
* **ENHANCEMENT:** adding github actions for automatic release
|
|
8
|
+
* **REFACTOR:** updating readthedocs settings
|
|
9
|
+
* **REFACTOR:** upgrading to `pyproject.toml` from `setup.py`
|
|
10
|
+
* **DOCS**: updating docs to use furo theme
|
|
11
|
+
|
|
4
12
|
**v2.7.8 - November 3, 2025**
|
|
5
13
|
|
|
6
14
|
* **REFACTOR:** adding some db.commits()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
title: fundamentals. Fundamental tools required by most self-respecting python-packages bundled in one place
|
|
3
|
+
message: If you use this software, please cite it as below.
|
|
4
|
+
authors:
|
|
5
|
+
- family-names: "Young"
|
|
6
|
+
given-names: "David R."
|
|
7
|
+
orcid: "https://orcid.org/0000-0002-1229-2499"
|
|
8
|
+
doi: 10.5281/zenodo.8037509
|
|
9
|
+
url: "https://zenodo.org/doi/10.5281/zenodo.8037509"
|
|
10
|
+
abstract: Some fundamental tools required by most self-respecting python-packages bundled in one place. Very opinionated project setup tools including logging, plain-text settings files and database connections.
|
|
11
|
+
keywords: [tooling]
|
|
12
|
+
license: GPL-3.0-only
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: fundamentals
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.8.1.dev0
|
|
4
4
|
Summary: Some fundamental tools required by most self-respecting python-packages bundled in one place. Very opinionated project setup tools including logging, plain-text settings files and database connections.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Author-email: davidrobertyoung@gmail.com
|
|
9
|
-
License: MIT
|
|
5
|
+
Author-email: David Young <david.young.rse@gmail.com>
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/thespacedoctor/fundamentals
|
|
10
8
|
Keywords: logging, database
|
|
11
9
|
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier:
|
|
13
|
-
Classifier:
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
14
12
|
Classifier: Topic :: Utilities
|
|
13
|
+
Requires-Python: >=3.11
|
|
15
14
|
Description-Content-Type: text/markdown
|
|
16
15
|
License-File: LICENSE
|
|
17
16
|
Requires-Dist: pyyaml
|
|
@@ -23,11 +22,39 @@ Requires-Dist: python-dateutil
|
|
|
23
22
|
Requires-Dist: requests
|
|
24
23
|
Requires-Dist: python-daemon
|
|
25
24
|
Requires-Dist: tqdm
|
|
25
|
+
Provides-Extra: docs
|
|
26
|
+
Requires-Dist: build; extra == "docs"
|
|
27
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
28
|
+
Requires-Dist: sphinx-autodoc2; extra == "docs"
|
|
29
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
30
|
+
Requires-Dist: furo; extra == "docs"
|
|
31
|
+
Requires-Dist: sphinx-inline-tabs; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinxext-opengraph; extra == "docs"
|
|
33
|
+
Requires-Dist: sphinx-autobuild; extra == "docs"
|
|
34
|
+
Requires-Dist: linkify-it-py; extra == "docs"
|
|
35
|
+
Requires-Dist: sphinxcontrib-mermaid; extra == "docs"
|
|
36
|
+
Requires-Dist: sphinx-togglebutton; extra == "docs"
|
|
37
|
+
Requires-Dist: sphinx_copybutton; extra == "docs"
|
|
38
|
+
Requires-Dist: sphinx_tippy; extra == "docs"
|
|
39
|
+
Requires-Dist: sphinx_design; extra == "docs"
|
|
40
|
+
Requires-Dist: pygments-csv-lexer; extra == "docs"
|
|
41
|
+
Requires-Dist: sphinxcontrib-svg2pdfconverter; extra == "docs"
|
|
42
|
+
Requires-Dist: sphinx-remove-toctrees; extra == "docs"
|
|
43
|
+
Requires-Dist: sphinxcontrib.bibtex; extra == "docs"
|
|
44
|
+
Provides-Extra: tests
|
|
45
|
+
Requires-Dist: pytest; extra == "tests"
|
|
46
|
+
Requires-Dist: pytest-cov; extra == "tests"
|
|
47
|
+
Requires-Dist: nose2; extra == "tests"
|
|
48
|
+
Provides-Extra: dev
|
|
49
|
+
Requires-Dist: fundamentals[docs,tests]; extra == "dev"
|
|
50
|
+
Requires-Dist: build; extra == "dev"
|
|
51
|
+
Requires-Dist: twine; extra == "dev"
|
|
52
|
+
Dynamic: license-file
|
|
26
53
|
|
|
27
54
|
# fundamentals
|
|
28
55
|
|
|
29
56
|
|
|
30
|
-
[](https://zenodo.org/doi/10.5281/zenodo.8037509)
|
|
57
|
+
[](https://zenodo.org/doi/10.5281/zenodo.8037509)
|
|
31
58
|
|
|
32
59
|
<!-- INFO BADGES -->
|
|
33
60
|
|
|
@@ -39,8 +66,8 @@ Requires-Dist: tqdm
|
|
|
39
66
|
|
|
40
67
|
<!-- STATUS BADGES -->
|
|
41
68
|
|
|
42
|
-
[](https://soxs-eso-data.org/ci/blue/organizations/jenkins/fundamentals/activity?branch=master)
|
|
70
|
+
[](https://soxs-eso-data.org/ci/blue/organizations/jenkins/fundamentals/activity?branch=develop)
|
|
44
71
|
[](https://raw.githack.com/thespacedoctor/fundamentals/master/htmlcov/index.html)
|
|
45
72
|
[](https://fundamentals.readthedocs.io/en/master/)
|
|
46
73
|
[](https://github.com/thespacedoctor/fundamentals/issues?q=is%3Aissue+is%3Aopen+label%3A%22type%3A+bug%22+)
|
|
@@ -49,9 +76,6 @@ Requires-Dist: tqdm
|
|
|
49
76
|
|
|
50
77
|
Documentation for fundamentals is hosted by [Read the Docs](https://fundamentals.readthedocs.io/en/master/) ([development version](https://fundamentals.readthedocs.io/en/develop/) and [master version](https://fundamentals.readthedocs.io/en/master/)). The code lives on [github](https://github.com/thespacedoctor/fundamentals). Please report any issues you find [here](https://github.com/thespacedoctor/fundamentals/issues).
|
|
51
78
|
|
|
52
|
-
## Features
|
|
53
|
-
|
|
54
|
-
*
|
|
55
79
|
|
|
56
80
|
## How to cite fundamentals
|
|
57
81
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# fundamentals
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
[](https://zenodo.org/doi/10.5281/zenodo.8037509)
|
|
4
|
+
[](https://zenodo.org/doi/10.5281/zenodo.8037509)
|
|
5
5
|
|
|
6
6
|
<!-- INFO BADGES -->
|
|
7
7
|
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
<!-- STATUS BADGES -->
|
|
15
15
|
|
|
16
|
-
[](https://soxs-eso-data.org/ci/blue/organizations/jenkins/fundamentals/activity?branch=master)
|
|
17
|
+
[](https://soxs-eso-data.org/ci/blue/organizations/jenkins/fundamentals/activity?branch=develop)
|
|
18
18
|
[](https://raw.githack.com/thespacedoctor/fundamentals/master/htmlcov/index.html)
|
|
19
19
|
[](https://fundamentals.readthedocs.io/en/master/)
|
|
20
20
|
[](https://github.com/thespacedoctor/fundamentals/issues?q=is%3Aissue+is%3Aopen+label%3A%22type%3A+bug%22+)
|
|
@@ -23,9 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
Documentation for fundamentals is hosted by [Read the Docs](https://fundamentals.readthedocs.io/en/master/) ([development version](https://fundamentals.readthedocs.io/en/develop/) and [master version](https://fundamentals.readthedocs.io/en/master/)). The code lives on [github](https://github.com/thespacedoctor/fundamentals). Please report any issues you find [here](https://github.com/thespacedoctor/fundamentals/issues).
|
|
25
25
|
|
|
26
|
-
## Features
|
|
27
|
-
|
|
28
|
-
*
|
|
29
26
|
|
|
30
27
|
## How to cite fundamentals
|
|
31
28
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '2.8.1.dev0'
|
|
@@ -5,7 +5,7 @@ Documentation for fundamentals can be found here: http://fundamentals.readthedoc
|
|
|
5
5
|
|
|
6
6
|
Usage:
|
|
7
7
|
fundamentals init
|
|
8
|
-
fundamentals [-s <pathToSettingsFile>]
|
|
8
|
+
fundamentals [-s <pathToSettingsFile>]
|
|
9
9
|
|
|
10
10
|
Options:
|
|
11
11
|
init setup the fundamentals settings file for the first time
|
|
@@ -13,9 +13,11 @@ Options:
|
|
|
13
13
|
-v, --version show version
|
|
14
14
|
-s, --settings <pathToSettingsFile> the settings file
|
|
15
15
|
"""
|
|
16
|
+
|
|
16
17
|
import sys
|
|
17
18
|
import os
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
os.environ["TERM"] = "vt100"
|
|
19
21
|
import readline
|
|
20
22
|
import glob
|
|
21
23
|
import pickle
|
|
@@ -25,7 +27,7 @@ from subprocess import Popen, PIPE, STDOUT
|
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
def tab_complete(text, state):
|
|
28
|
-
return (glob.glob(text +
|
|
30
|
+
return (glob.glob(text + "*") + [None])[state]
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
def main(arguments=None):
|
|
@@ -39,12 +41,12 @@ def main(arguments=None):
|
|
|
39
41
|
logLevel="WARNING",
|
|
40
42
|
options_first=False,
|
|
41
43
|
projectName="fundamentals",
|
|
42
|
-
defaultSettingsFile=True
|
|
44
|
+
defaultSettingsFile=True,
|
|
43
45
|
)
|
|
44
46
|
arguments, settings, log, dbConn = su.setup()
|
|
45
47
|
|
|
46
48
|
# tab completion for raw_input
|
|
47
|
-
readline.set_completer_delims(
|
|
49
|
+
readline.set_completer_delims(" \t\n;")
|
|
48
50
|
readline.parse_and_bind("tab: complete")
|
|
49
51
|
readline.set_completer(tab_complete)
|
|
50
52
|
|
|
@@ -60,13 +62,17 @@ def main(arguments=None):
|
|
|
60
62
|
if arg == "--dbConn":
|
|
61
63
|
dbConn = val
|
|
62
64
|
a["dbConn"] = val
|
|
63
|
-
log.debug(
|
|
65
|
+
log.debug(
|
|
66
|
+
"%s = %s"
|
|
67
|
+
% (
|
|
68
|
+
varname,
|
|
69
|
+
val,
|
|
70
|
+
)
|
|
71
|
+
)
|
|
64
72
|
|
|
65
73
|
## START LOGGING ##
|
|
66
74
|
startTime = times.get_now_sql_datetime()
|
|
67
|
-
log.info(
|
|
68
|
-
'--- STARTING TO RUN THE cl_utils.py AT %s' %
|
|
69
|
-
(startTime,))
|
|
75
|
+
log.info("--- STARTING TO RUN THE cl_utils.py AT %s" % (startTime,))
|
|
70
76
|
|
|
71
77
|
# set options interactively if user requests
|
|
72
78
|
if "interactiveFlag" in a and a["interactiveFlag"]:
|
|
@@ -98,6 +104,7 @@ def main(arguments=None):
|
|
|
98
104
|
|
|
99
105
|
if a["init"]:
|
|
100
106
|
from os.path import expanduser
|
|
107
|
+
|
|
101
108
|
home = expanduser("~")
|
|
102
109
|
filepath = home + "/.config/fundamentals/fundamentals.yaml"
|
|
103
110
|
try:
|
|
@@ -120,10 +127,16 @@ def main(arguments=None):
|
|
|
120
127
|
## FINISH LOGGING ##
|
|
121
128
|
endTime = times.get_now_sql_datetime()
|
|
122
129
|
runningTime = times.calculate_time_difference(startTime, endTime)
|
|
123
|
-
log.info(
|
|
124
|
-
|
|
130
|
+
log.info(
|
|
131
|
+
"-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --"
|
|
132
|
+
% (
|
|
133
|
+
endTime,
|
|
134
|
+
runningTime,
|
|
135
|
+
)
|
|
136
|
+
)
|
|
125
137
|
|
|
126
138
|
return
|
|
127
139
|
|
|
128
|
-
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
129
142
|
main()
|
|
@@ -3,27 +3,29 @@
|
|
|
3
3
|
"""
|
|
4
4
|
*helper class to daemonise you code*
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Author
|
|
7
|
+
: David Young
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Date Created
|
|
10
|
+
: May 23, 2023
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
from fundamentals import tools
|
|
14
14
|
from builtins import object
|
|
15
15
|
import sys
|
|
16
16
|
import os
|
|
17
|
-
os.environ['TERM'] = 'vt100'
|
|
18
17
|
|
|
18
|
+
os.environ["TERM"] = "vt100"
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
class daemonise:
|
|
21
22
|
"""
|
|
22
23
|
A class to daemonise a python code
|
|
23
24
|
|
|
24
25
|
**Key Arguments:**
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
- ``log`` -- logger
|
|
28
|
+
- ``name`` -- a name for the daemon (e.g. python package name)
|
|
27
29
|
|
|
28
30
|
**Usage:**
|
|
29
31
|
|
|
@@ -37,7 +39,7 @@ class daemonise():
|
|
|
37
39
|
start start the myCommand daemon
|
|
38
40
|
stop stop the myCommand daemon
|
|
39
41
|
restart restart the myCommand daemon
|
|
40
|
-
status print the staus of the myCommand daemon
|
|
42
|
+
status print the staus of the myCommand daemon
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
and then when executing the commands:
|
|
@@ -76,17 +78,13 @@ class daemonise():
|
|
|
76
78
|
|
|
77
79
|
"""
|
|
78
80
|
|
|
79
|
-
def __init__(
|
|
80
|
-
self,
|
|
81
|
-
log,
|
|
82
|
-
name,
|
|
83
|
-
**akws
|
|
84
|
-
):
|
|
81
|
+
def __init__(self, log, name, **akws):
|
|
85
82
|
self.log = log
|
|
86
83
|
log.debug("instantiating a new 'daemonise' object")
|
|
87
84
|
|
|
88
85
|
# MAKE ROOT DIR
|
|
89
86
|
from os.path import expanduser
|
|
87
|
+
|
|
90
88
|
home = expanduser("~")
|
|
91
89
|
self.rootDir = home + f"/.config/{name}/"
|
|
92
90
|
if not os.path.exists(self.rootDir):
|
|
@@ -101,9 +99,8 @@ class daemonise():
|
|
|
101
99
|
return
|
|
102
100
|
|
|
103
101
|
def start(self):
|
|
104
|
-
"""start the daemonise running
|
|
105
|
-
""
|
|
106
|
-
self.log.info('starting the ``get`` method')
|
|
102
|
+
"""start the daemonise running"""
|
|
103
|
+
self.log.info("starting the ``get`` method")
|
|
107
104
|
|
|
108
105
|
import time
|
|
109
106
|
import signal
|
|
@@ -112,7 +109,7 @@ class daemonise():
|
|
|
112
109
|
|
|
113
110
|
running = False
|
|
114
111
|
if os.path.exists(self.pidFile):
|
|
115
|
-
with open(self.pidFile, mode=
|
|
112
|
+
with open(self.pidFile, mode="r") as f:
|
|
116
113
|
pid = int(f.read().strip())
|
|
117
114
|
try:
|
|
118
115
|
os.kill(pid, 0)
|
|
@@ -139,58 +136,51 @@ class daemonise():
|
|
|
139
136
|
working_directory=self.rootDir,
|
|
140
137
|
umask=0o002,
|
|
141
138
|
pidfile=pidfile.TimeoutPIDLockFile(self.pidFile),
|
|
142
|
-
stdout=open(self.outLog,
|
|
143
|
-
stderr=open(self.errLog,
|
|
144
|
-
signal_map={signal.SIGTERM: self.cleanup}
|
|
139
|
+
stdout=open(self.outLog, "a"),
|
|
140
|
+
stderr=open(self.errLog, "a"),
|
|
141
|
+
signal_map={signal.SIGTERM: self.cleanup},
|
|
145
142
|
) as context:
|
|
146
143
|
self.action(**self.akws)
|
|
147
144
|
|
|
148
|
-
self.log.info(
|
|
145
|
+
self.log.info("completed the ``get`` method")
|
|
149
146
|
return None
|
|
150
147
|
|
|
151
|
-
def cleanup(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
frame):
|
|
155
|
-
"""*the code to run when daemon is killed*
|
|
156
|
-
"""
|
|
157
|
-
self.log.debug('starting the ``cleanup`` method')
|
|
148
|
+
def cleanup(self, signum, frame):
|
|
149
|
+
"""*the code to run when daemon is killed*"""
|
|
150
|
+
self.log.debug("starting the ``cleanup`` method")
|
|
158
151
|
|
|
159
152
|
from datetime import datetime, date, time
|
|
153
|
+
|
|
160
154
|
now = datetime.now()
|
|
161
155
|
now = now.strftime("%Y%m%dt%H%M%S")
|
|
162
156
|
|
|
163
157
|
print(f"{self.name} daemon stopped at {now}")
|
|
164
158
|
sys.exit(0)
|
|
165
159
|
|
|
166
|
-
self.log.debug(
|
|
160
|
+
self.log.debug("completed the ``cleanup`` method")
|
|
167
161
|
return None
|
|
168
162
|
|
|
169
|
-
def action(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"""*the code to execute in daemon mode, this method should be overriden to execute novel code*
|
|
173
|
-
"""
|
|
174
|
-
self.log.debug('starting the ``action`` method')
|
|
163
|
+
def action(self, **akws):
|
|
164
|
+
"""*the code to execute in daemon mode, this method should be overriden to execute novel code*"""
|
|
165
|
+
self.log.debug("starting the ``action`` method")
|
|
175
166
|
|
|
176
167
|
import time
|
|
168
|
+
|
|
177
169
|
while True:
|
|
178
170
|
print("ACTION")
|
|
179
171
|
time.sleep(3)
|
|
180
172
|
|
|
181
|
-
self.log.debug(
|
|
173
|
+
self.log.debug("completed the ``action`` method")
|
|
182
174
|
return None
|
|
183
175
|
|
|
184
|
-
def stop(
|
|
185
|
-
|
|
186
|
-
"
|
|
187
|
-
"""
|
|
188
|
-
self.log.debug('starting the ``stop`` method')
|
|
176
|
+
def stop(self):
|
|
177
|
+
"""*stop the daemon and cleanup*"""
|
|
178
|
+
self.log.debug("starting the ``stop`` method")
|
|
189
179
|
|
|
190
180
|
import signal
|
|
191
181
|
|
|
192
182
|
if os.path.exists(self.pidFile):
|
|
193
|
-
with open(self.pidFile, mode=
|
|
183
|
+
with open(self.pidFile, mode="r") as f:
|
|
194
184
|
pid = f.read().strip()
|
|
195
185
|
try:
|
|
196
186
|
os.kill(int(pid), signal.SIGTERM)
|
|
@@ -200,17 +190,15 @@ class daemonise():
|
|
|
200
190
|
else:
|
|
201
191
|
print(f"{self.name} daemon is not running.")
|
|
202
192
|
|
|
203
|
-
self.log.debug(
|
|
193
|
+
self.log.debug("completed the ``stop`` method")
|
|
204
194
|
return None
|
|
205
195
|
|
|
206
|
-
def status(
|
|
207
|
-
|
|
208
|
-
"
|
|
209
|
-
"""
|
|
210
|
-
self.log.debug('starting the ``status`` method')
|
|
196
|
+
def status(self):
|
|
197
|
+
"""*print the status of the daemon*"""
|
|
198
|
+
self.log.debug("starting the ``status`` method")
|
|
211
199
|
|
|
212
200
|
if os.path.exists(self.pidFile):
|
|
213
|
-
with open(self.pidFile, mode=
|
|
201
|
+
with open(self.pidFile, mode="r") as f:
|
|
214
202
|
pid = int(f.read().strip())
|
|
215
203
|
try:
|
|
216
204
|
os.kill(pid, 0)
|
|
@@ -222,16 +210,15 @@ class daemonise():
|
|
|
222
210
|
else:
|
|
223
211
|
print(f"{self.name} daemon is not running.")
|
|
224
212
|
|
|
225
|
-
self.log.debug(
|
|
213
|
+
self.log.debug("completed the ``status`` method")
|
|
226
214
|
return None
|
|
227
215
|
|
|
228
|
-
def restart(
|
|
229
|
-
|
|
230
|
-
"
|
|
231
|
-
"""
|
|
232
|
-
self.log.debug('starting the ``status`` method')
|
|
216
|
+
def restart(self):
|
|
217
|
+
"""*stop and start the daemon*"""
|
|
218
|
+
self.log.debug("starting the ``status`` method")
|
|
233
219
|
|
|
234
220
|
import time
|
|
221
|
+
|
|
235
222
|
self.stop()
|
|
236
223
|
|
|
237
224
|
iteration = 0
|
|
@@ -241,5 +228,5 @@ class daemonise():
|
|
|
241
228
|
|
|
242
229
|
self.start()
|
|
243
230
|
|
|
244
|
-
self.log.debug(
|
|
231
|
+
self.log.debug("completed the ``status`` method")
|
|
245
232
|
return None
|