Skip to content

Commit 2ece10c

Browse files
committed
Add more docs
1 parent eefb55d commit 2ece10c

File tree

15 files changed

+186
-10
lines changed

15 files changed

+186
-10
lines changed

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"njpwerner.autodocstring",
4+
"ms-python.python"
5+
]
6+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"autoDocstring.docstringFormat": "sphinx"
3+
}

docs/index.rst

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ Particularly, some `appliances (Proxmox, XCP-ng and KVM) are prepared <https://d
3333
python/shares.rst
3434
python/computer.rst
3535
python/config.rst
36+
python/environment.rst
37+
python/fileHelper.rst
38+
python/gpo.rst
39+
python/hooks.rst
40+
python/imageHelper.rst

docs/python/config.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Module: config
33

44
This module is used to deal with all config files:
55

6-
* `/etc/linuxmusterLinuxclient7/network.conf`
6+
* `/etc/linuxmuster-linuxclient7/network.conf`
77

88
Members
99
=======

docs/python/environment.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Module: environment
2+
*******************
3+
4+
This module is used to export and unset environment variables during the onLogin/logon hook.
5+
6+
Members
7+
=======
8+
.. automodule:: linuxmusterLinuxclient7.environment
9+
:members:

docs/python/fileHelper.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Module: fileHelper
2+
******************
3+
4+
This module is used to deal files.
5+
6+
Members
7+
=======
8+
.. automodule:: linuxmusterLinuxclient7.fileHelper
9+
:members:

docs/python/gpo.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Module: gpo
2+
***********
3+
4+
This module is used to deal with Microsoft GPOs.
5+
6+
Members
7+
=======
8+
.. automodule:: linuxmusterLinuxclient7.gpo
9+
:members:

docs/python/hooks.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Module: hooks
2+
*************
3+
4+
This module is used to deal with local hookdirs in `/etc/linuxmuster-linuxclient7` and the sysvol.
5+
6+
Members
7+
=======
8+
.. automodule:: linuxmusterLinuxclient7.hooks
9+
:members:

docs/python/imageHelper.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Module: imageHelper
2+
*******************
3+
4+
This module is used to prepare a client for imaging.
5+
6+
Members
7+
=======
8+
.. automodule:: linuxmusterLinuxclient7.imageHelper
9+
:members:

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def network():
55
"""
6-
Get the network configuration in `/etc/linuxmusterLinuxclient7/network.conf`
6+
Get the network configuration in `/etc/linuxmuster-linuxclient7/network.conf`
77
88
:return: Tuple (success, dict of keys)
99
:rtype: tuple
@@ -30,7 +30,7 @@ def network():
3030

3131
def writeNetworkConfig(newNetworkConfig):
3232
"""
33-
Write the network configuration in `/etc/linuxmusterLinuxclient7/network.conf`
33+
Write the network configuration in `/etc/linuxmuster-linuxclient7/network.conf`
3434
3535
:param newNetworkConfig: The new config
3636
:type newNetworkConfig: dict
@@ -64,7 +64,7 @@ def writeNetworkConfig(newNetworkConfig):
6464

6565
def upgrade():
6666
"""
67-
Upgrade the format of the network configuration in `/etc/linuxmusterLinuxclient7/network.conf`
67+
Upgrade the format of the network configuration in `/etc/linuxmuster-linuxclient7/network.conf`
6868
This is done automatically on package upgrades.
6969
7070
:return: True or False

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/environment.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
from linuxmusterLinuxclient7 import constants, user, logging
33

44
def export(keyValuePair):
5+
"""
6+
Export an environment variable
7+
8+
:param keyValuePair: Key value pair in format `key=value`
9+
:type keyValuePait: str
10+
:return: True or False
11+
:rtype: bool
12+
"""
513
logging.debug("Saving export '{}' to tmp file".format(keyValuePair))
614

715
envList = keyValuePair.split("=")
@@ -10,9 +18,17 @@ def export(keyValuePair):
1018

1119
return _appendToTmpEnvFile("export", keyValuePair)
1220

13-
def unset(keyValuePair):
14-
logging.debug("Saving unset '{}' to tmp file".format(keyValuePair))
15-
return _appendToTmpEnvFile("unset", keyValuePair)
21+
def unset(key):
22+
"""
23+
Unset a previously exported environment variable
24+
25+
:param key: The key to unset
26+
:type key: str
27+
:return: True or False
28+
:rtype: bool
29+
"""
30+
logging.debug("Saving unset '{}' to tmp file".format(key))
31+
return _appendToTmpEnvFile("unset", key)
1632

1733
# --------------------
1834
# - Helper functions -

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/fileHelper.py

+45
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
from linuxmusterLinuxclient7 import logging
33

44
def removeLinesInFileContainingString(filePath, forbiddenStrings):
5+
"""
6+
Remove all lines containing a given string form a file.
7+
8+
:param filePath: The path to the file
9+
:type filePath: str
10+
:param forbiddenStrings: The string to search for
11+
:type forbiddenStrings: str
12+
:return: True on success, False otherwise
13+
:rtype: bool
14+
"""
515
if not isinstance(forbiddenStrings, list):
616
forbiddenStrings = [forbiddenStrings]
717

@@ -33,6 +43,14 @@ def removeLinesInFileContainingString(filePath, forbiddenStrings):
3343
return True
3444

3545
def deleteFile(filePath):
46+
"""
47+
Delete a file
48+
49+
:param filePath: The path of the file
50+
:type filePath: str
51+
:return: True on success, False otherwise
52+
:rtype: bool
53+
"""
3654
try:
3755
if os.path.exists(filePath):
3856
os.unlink(filePath)
@@ -43,6 +61,16 @@ def deleteFile(filePath):
4361
return False
4462

4563
def deleteFilesWithExtension(directory, extension):
64+
"""
65+
Delete all files with a given extension in a given directory.
66+
67+
:param directory: The path of the directory
68+
:type directory: str
69+
:param extension: The file extension
70+
:type extension: str
71+
:return: True on success, False otherwise
72+
:rtype: bool
73+
"""
4674
if directory.endswith("/"):
4775
directory = directory[:-1]
4876

@@ -61,13 +89,30 @@ def deleteFilesWithExtension(directory, extension):
6189
return True
6290

6391
def deleteDirectory(directory):
92+
"""
93+
Recoursively delete a directory.
94+
95+
:param directory: The path of the directory
96+
:type directory: bool
97+
:return: True on success, False otherwise
98+
:rtype: bool
99+
"""
64100
try:
65101
shutil.rmtree(directory)
66102
except:
67103
return False
68104
return True
69105

70106
def deleteAllInDirectory(directory):
107+
"""
108+
Delete all files in a given directory
109+
110+
:param directory: The path of the directory
111+
:type directory: str
112+
:return: True on success, False otherwise
113+
:rtype: bool
114+
"""
115+
71116
if directory.endswith("/"):
72117
directory = directory[:-1]
73118

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/gpo.py

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from linuxmusterLinuxclient7 import logging, constants, config, user, ldapHelper, shares, computer, printers
99

1010
def processAllPolicies():
11+
"""
12+
Process all applicable policies (equivalent to gpupdate on windows)
13+
14+
:return: True on success, False otherwise
15+
:rtype: bool
16+
"""
1117
rc, policyDnList = _findApplicablePolicies()
1218
if not rc:
1319
logging.error("Error when loading applicable GPOs")

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/hooks.py

+46-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,25 @@
77
from linuxmusterLinuxclient7 import logging, constants, user, config, computer, environment, setup, shares
88

99
class Type(Enum):
10+
"""
11+
Enum containing all hook types
12+
"""
13+
1014
Boot = 0
15+
"""The onBoot hook
16+
"""
1117
Shutdown = 1
18+
"""The on Shutdown hook
19+
"""
1220
LoginAsRoot = 2
21+
"""The onLoginAsRoot hook
22+
"""
1323
Login = 3
24+
"""The onLogin hook
25+
"""
1426
SessionStarted = 4
27+
"""The onSession started hook
28+
"""
1529
LogoutAsRoot = 5
1630
LoginLogoutAsRoot = 6
1731

@@ -30,6 +44,12 @@ class Type(Enum):
3044
}
3145

3246
def runLocalHook(hookType):
47+
"""
48+
Run all scripts in a local hookdir
49+
50+
:param hookType: The type of hook to run
51+
:type hookType: hooks.Type
52+
"""
3353
logging.info("=== Running local hook on{0} ===".format(hookType.name))
3454
hookDir = _getLocalHookDir(hookType)
3555
if os.path.exists(hookDir):
@@ -41,6 +61,12 @@ def runLocalHook(hookType):
4161

4262

4363
def runRemoteHook(hookType):
64+
"""
65+
Run hookscript from sysvol
66+
67+
:param hookType: The type of hook to run
68+
:type hookType: hooks.Type
69+
"""
4470
logging.info("=== Running remote hook on{0} ===".format(hookType.name))
4571
rc, hookScripts = _getRemoteHookScripts(hookType)
4672

@@ -52,16 +78,33 @@ def runRemoteHook(hookType):
5278
logging.info("===> Finished running remote hook on{0} ===".format(hookType.name))
5379

5480
def runHook(hookType):
81+
"""
82+
Executes hooks.runLocalHook() and hooks.runRemoteHook()
83+
84+
:param hookType: The type of hook to run
85+
:type hookType: hooks.Type
86+
"""
5587
runLocalHook(hookType)
5688
runRemoteHook(hookType)
5789

5890
def getLocalHookScript(hookType):
59-
return "{0}/on{1}".format(constants.scriptDir,hookType.name)
91+
"""Get the path of a local hookscript
6092
61-
def createSessionAutostartFile():
62-
pass
93+
:param hookType: The type of hook script to get the path for
94+
:type hookType: hooks.Type
95+
:return: The path
96+
:rtype: str
97+
"""
98+
return "{0}/on{1}".format(constants.scriptDir,hookType.name)
6399

64100
def shouldHooksBeExecuted(overrideUsername=None):
101+
"""Check if hooks should be executed
102+
103+
:param overrideUsername: Override the username to check, defaults to None
104+
:type overrideUsername: str, optional
105+
:return: True if hooks should be executed, fale otherwise
106+
:rtype: bool
107+
"""
65108
# check if linuxmuster-linuxclient7 is setup
66109
if not setup.isSetup():
67110
logging.info("==== Linuxmuster-linuxclient7 is not setup, exiting ====")

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/imageHelper.py

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
from linuxmusterLinuxclient7 import logging, setup, realm, user, constants, printers, fileHelper
33

44
def prepareForImage(unattended=False):
5+
"""Prepare the computer for creating an image
6+
7+
:param unattended: If set to True, all questions will be answered with yes, defaults to False
8+
:type unattended: bool, optional
9+
:return: True on success, False otherwise
10+
:rtype: bool
11+
"""
512
logging.info("#### Image preparation ####")
613

714
try:

0 commit comments

Comments
 (0)