Skip to content

Commit 7365266

Browse files
author
Jared Manning
committed
Tidy up comments and syntax, also add main() func.
1 parent aefe4c1 commit 7365266

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

daily_checks.py

+42-36
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
# Script Name : daily_checks.py
2-
# Author : Craig Richards
3-
# Created : 07th December 2011
4-
# Last Modified : 01st May 2013
5-
# Version : 1.4
1+
# Script Name : daily_checks.py
2+
# Author : Craig Richards
3+
# Created : 07th December 2011
4+
# Last Modified : 01st May 2013
5+
# Version : 1.5
6+
#
7+
# Modifications : 1.1 Removed the static lines for the putty sessions, it now reads a file, loops through and makes the connections.
8+
# : 1.2 Added a variable filename=sys.argv[0] , as when you use __file__ it errors when creating an exe with py2exe.
9+
# : 1.3 Changed the server_list.txt file name and moved the file to the config directory.
10+
# : 1.4 Changed some settings due to getting a new pc
11+
# : 1.5 Tidy comments and syntax
12+
#
13+
# Description : This simple script loads everything I need to carry out the daily checks for our systems.
614

7-
# Modifications : 1.1 Removed the static lines for the putty sessions, it now reads a file, loops through and makes the connections.
8-
# : 1.2 Added a variable filename=sys.argv[0] , as when you use __file__ it errors when creating an exe with py2exe.
9-
# : 1.3 Changed the server_list.txt file name and moved the file to the config directory.
10-
# : 1.4 Changed some settings due to getting a new pc
11-
12-
# Description : This simple script loads everything I need to carry out the daily checks for our systems.
13-
14-
import platform # Load the Library Module
15-
import os # Load the Library Module
16-
import subprocess # Load the Library Module
17-
import sys # Load the Library Module
15+
import platform # Load Modules
16+
import os
17+
import subprocess
18+
import sys
1819

1920
from time import strftime # Load just the strftime Module from Time
2021

21-
def clear_screen(): # Function to clear the screen
22-
if os.name == "posix": # Unix/Linux/MacOS/BSD/etc
23-
os.system('clear') # Clear the Screen
22+
def clear_screen(): # Function to clear the screen
23+
if os.name == "posix": # Unix/Linux/MacOS/BSD/etc
24+
os.system('clear') # Clear the Screen
2425
elif os.name in ("nt", "dos", "ce"): # DOS/Windows
25-
os.system('CLS') # Clear the Screen
26+
os.system('CLS') # Clear the Screen
2627

27-
def print_docs(): # Function to print the daily checks automatically
28+
def print_docs(): # Function to print the daily checks automatically
2829
print "Printing Daily Check Sheets:"
2930
# The command below passes the command line string to open word, open the document, print it then close word down
3031
subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate()
3132

32-
def putty_sessions(): # Function to load the putty sessions I need
33-
for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename
34-
subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1
33+
def putty_sessions(): # Function to load the putty sessions I need
34+
for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename
35+
subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1
3536

3637
def rdp_sessions():
3738
print "Loading RDP Sessions:"
38-
subprocess.Popen("mstsc eclr.rdp") # Open up a terminal session connection and load the euroclear session
39+
subprocess.Popen("mstsc eclr.rdp") # Open up a terminal session connection and load the euroclear session
3940

4041
def euroclear_docs():
4142
# The command below opens IE and loads the Euroclear password document
@@ -44,15 +45,20 @@ def euroclear_docs():
4445
# End of the functions
4546

4647
# Start of the Main Program
48+
def main():
49+
filename = sys.argv[0] # Create the variable filename
50+
confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.3
51+
conffile = ('daily_checks_servers.conf') # Set the variable conffile - 1.3
52+
conffilename = os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.3
53+
clear_screen() # Call the clear screen function
54+
55+
# The command below prints a little welcome message, as well as the script name, the date and time and where it was run from.
56+
print "Good Morning " + os.getenv('USERNAME') + ", " + filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd()
57+
58+
print_docs() # Call the print_docs function
59+
putty_sessions() # Call the putty_session function
60+
rdp_sessions() # Call the rdp_sessions function
61+
euroclear_docs() # Call the euroclear_docs function
4762

48-
filename=sys.argv[0] # Create the variable filename
49-
confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.3
50-
conffile = ('daily_checks_servers.conf') # Set the variable conffile - 1.3
51-
conffilename=os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.3
52-
clear_screen() # Call the clear screen function
53-
# The command below prints a little welcome message, as well as the script name, the date and time and where it was run from.
54-
print "Good Morning " + os.getenv('USERNAME') + ", " + filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd()
55-
print_docs() # Call the print_docs function
56-
putty_sessions() # Call the putty_session function
57-
rdp_sessions() # Call the rdp_sessions function
58-
euroclear_docs() # Call the euroclear_docs function
63+
if __name__ == '__main__':
64+
main()

0 commit comments

Comments
 (0)