Skip to content

Commit 491690d

Browse files
committed
Merge branch 'devel'
2 parents 9983143 + 89feb29 commit 491690d

3 files changed

Lines changed: 36 additions & 16 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ If an option is not specified in the CLI, it is read from the headnode_notifier.
4848
4. /path/to/password_file
4949

5050

51+
* Config content:
52+
53+
```
54+
[server]
55+
address = smtp.gmail.com
56+
port = 587
57+
58+
[mailbox]
59+
address =
60+
password_file =
61+
```
62+
63+
64+
* Config location: **$HOME**
65+
66+
67+
* Config name:
68+
69+
```
70+
.headnode_notifier.config
71+
```
72+
5173
#### Password handling
5274

5375
In order to avoid storing the password anywhere in the script, it is read from file. You can specify the path using ```--password-file /path/to/file``` or in the config file. Remember that the **password file is plain text** so use the script with caution.

headnode_notifier.config

Lines changed: 0 additions & 7 deletions
This file was deleted.

headnode_notifier.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from email.MIMEBase import MIMEBase
88
from email import encoders
99
import argparse
10-
import sys
10+
import os
1111
import ConfigParser
1212

1313

1414
__author__ = "Dariusz Izak"
15-
__version__ = "1.2"
15+
__version__ = "1.3"
1616

1717

1818
def read_passwd_file(pass_file):
@@ -130,13 +130,15 @@ def main():
130130
Do NOT use with your personal account!")
131131
args = parser.parse_args()
132132

133-
config = ConfigParser.SafeConfigParser()
134-
config.read(sys.argv[0].replace(sys.argv[0].split("/")[-1],
135-
"headnode_notifier.config"))
136-
conf_serv_addr = config.get("server", "address")
137-
conf_port = config.get("server", "port")
138-
conf_from_addr = config.get("mailbox", "address")
139-
conf_passwd = config.get("mailbox", "password_file")
133+
home = os.path.expanduser("~")
134+
config_file_name = ".headnode_notifier.config"
135+
if os.path.isfile("{}/{}".format(home, config_file_name)) is True:
136+
config = ConfigParser.SafeConfigParser()
137+
config.read("{}/{}".format(home, config_file_name))
138+
conf_serv_addr = config.get("server", "address")
139+
conf_port = config.get("server", "port")
140+
conf_from_addr = config.get("mailbox", "address")
141+
conf_passwd = config.get("mailbox", "password_file")
140142

141143
if args.password_file is None:
142144
passwd = conf_passwd
@@ -154,6 +156,9 @@ def main():
154156
from_addr = args.from_addr
155157
else:
156158
from_addr = conf_from_addr
159+
if None or "" in [passwd, serv_addr, port, from_addr]:
160+
print "Missing values for password, server address, port or mailbox.\nPlease check your config file or CLI arguments.\nQuitting..."
161+
exit()
157162
passwd_from_file = read_passwd_file(passwd)
158163
send_mail(to_addr=args.to,
159164
subj_msg=args.subject,

0 commit comments

Comments
 (0)