Skip to content

Commit

Permalink
Merge pull request #84 from EBISPOT/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jdhayhurst authored Sep 30, 2021
2 parents a340cd1 + b3957e1 commit d8a3cea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM python:3.7-slim-buster
COPY . .

RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc openssh-client python-dev libmagic-dev \
&& apt-get install -y --no-install-recommends gcc openssh-client python-dev libmagic-dev rsync\
&& rm -rf /var/lib/apt/lists/* \
&& pip install -r requirements.txt \
&& apt-get purge -y --auto-remove gcc python-dev
19 changes: 13 additions & 6 deletions ftpSummaryStatsScript/ftp_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from pathlib import Path
import logging
import shutil
import smtplib
from email.message import EmailMessage


logging.basicConfig(
Expand Down Expand Up @@ -235,13 +237,17 @@ def remove_unexepcted_from_ftp(self):
self.move_study_from_ftp_to_staging(study)


def sendEmailReport(logs, emailAddresses):
def sendEmailReport(logs, emailFrom, emailTo):
try:
with open(logs, 'r') as f:
report = f.read()
mailBody = 'Subject: Summary Stats release report\nTo: {}\n{}'.format(emailAddresses,report)
p = Popen(["sendmail", "-t", "-oi", emailAddresses], stdin=PIPE)
p.communicate(mailBody.encode('utf-8'))
msg = EmailMessage()
msg.set_content(f.read())
msg['Subject'] = 'Summary Stats release report'
msg['From'] = emailFrom
msg['To'] = emailTo
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
except OSError as e:
logger.error(e)

Expand All @@ -253,6 +259,7 @@ def main():
parser.add_argument('--apiURL', type=str, help='URL base for curation REST API')
parser.add_argument('--test', action='store_true', help='If test run is specified, no release is done just send notification.')
parser.add_argument('--emailRecipient', type=str, help='Email address where the notification is sent.')
parser.add_argument('--emailFrom', type=str, help='Email address where the notification is from.')
args = parser.parse_args()
logger.info("============ FTP sync report =============")
sumstats_sync = SummaryStatsSync(staging_path = args.stagingDir,
Expand All @@ -274,7 +281,7 @@ def main():
logger.info("==========================================")
logger.info("Unexpected on staging: {}".format(list(sumstats_sync.unexpected_on_staging)))
logger.info("==========================================")
sendEmailReport("ftpsync.log", args.emailRecipient)
sendEmailReport("ftpsync.log", emailFrom=args.emailFrom, emailTo=args.emailRecipient)


if __name__ == '__main__':
Expand Down

0 comments on commit d8a3cea

Please sign in to comment.