diff --git a/deps/mail.py b/deps/mail.py new file mode 100644 index 0000000..fc10085 --- /dev/null +++ b/deps/mail.py @@ -0,0 +1,36 @@ +#!/usr/bin/python -u + +import sys +import smtplib + +job_id = sys.argv[1] +sender = sys.argv[2] +password = sys.argv[3] +receivers = sys.argv[4::] + +recips = "" +for guy in receivers: + recips = recips + guy + "," + +message = "From: Instrument Control <" + sender + ">" + "\n" +message = message + "To: " + recips + "\n" +message = message + "Subject: Sweep job " + job_id + "\n" + +msg = sys.stdin.readline() +while msg: + message = message + msg + msg = sys.stdin.readline() + +smtpObj = smtplib.SMTP_SSL("smtp.gmail.com", 465) +smtpObj.ehlo(sender) +smtpObj.starttls() +smtpObj.ehlo(sender) +smtpObj.login(sender, password) +failed = smtpObj.sendmail(sender, receivers, message) +if failed: + smtpObj.close() + exit(-1) +else: + smtpObj.close() + exit(0) +end \ No newline at end of file diff --git a/src/ICDataServer.jl b/src/ICDataServer.jl index 4ccc856..5266d3a 100644 --- a/src/ICDataServer.jl +++ b/src/ICDataServer.jl @@ -1,7 +1,7 @@ module ICDataServer using ICCommon -using Plots +# using Plots using JSON import ZMQ import ODBC @@ -15,30 +15,33 @@ export newjob, updatejob const ctx = ZMQ.Context() const jobsock = ZMQ.Socket(ctx, ZMQ.REP) -confpath = joinpath(Pkg.dir("ICDataServer"), "deps", "config.json") +confpath = joinpath(dirname(dirname(@__FILE__)), "deps", "config.json") if isfile(confpath) - confd = JSON.parsefile(confpath) - if reduce(&, k in keys(confd) for k in - ("jobsock", "dsn", "username", "password")) - - ZMQ.bind(jobsock, confd["jobsock"]) - const dsn = ODBC.DSN(confd["dsn"], confd["username"], confd["password"]) - else - if !"jobsock" in keys(confd) - error("set `jobsock` key in $(confpath) to have a valid ", - "ZeroMQ connection string.") - elseif !"dsn" in keys(confd) - error("set `dsn` key in $(confpath) to have a valid DSN identifier.") - elseif !"username" in keys(confd) - error("set `username` key in $(confpath) to a valid username.") - else - error("set `password` key in $(confpath) for the given user.") - end + const confd = JSON.parsefile(confpath) + if !haskey(confd, "jobsock") + error("set `jobsock` key in $(confpath) to have a valid ", + "ZeroMQ connection string.") + elseif !haskey(confd, "dsn") + error("set `dsn` key in $(confpath) to the name of a valid ODBC DSN.") + end + + if haskey(confd, "password") && !haskey(confd, "username") + error("set `username` key in $(confpath) if providing a `password` key.") + end + + if !haskey(confd, "username") + confd["username"] = "" + end + if !haskey(confd, "password") + confd["password"] = "" end else - error("config file not found at $(confpath).") + error("configuration file not found at $(confpath).") end +const dsn = ODBC.DSN(confd["dsn"], confd["username"], confd["password"]) +ZMQ.bind(jobsock, confd["jobsock"]) + function serve(;debug=false) while true msg = ZMQ.recv(jobsock)