Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bioinfo-doc updates: email password in yml and delivery notes in text file #207

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ Code contributions to the hotfix:

### Template fixes and updates

- Added blast_nt template to services.json

### Modules

#### Added enhancements

- [#207](https://github.com/BU-ISCIII/buisciii-tools/pull/207) - Bioinfo-doc updates: email password can be given in buisciii_config.yml and delivery notes in a text file

#### Fixes

#### Changed
Expand Down
6 changes: 4 additions & 2 deletions bu_isciii/__main__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_bu_isciii():
)

# stderr.print("[green] `._,._,'\n", highlight=False)
__version__ = "1.0.1"
__version__ = "2.0.0"
stderr.print(
"[grey39] BU-ISCIII-tools version {}".format(__version__), highlight=False
)
Expand Down Expand Up @@ -507,6 +507,7 @@ def bioinfo_doc(
"""
Create the folder documentation structure in bioinfo_doc server
"""
email_pass = email_psswd if email_psswd else ctx.obj.get("email_password")
new_doc = bu_isciii.bioinfo_doc.BioinfoDoc(
type,
resolution,
Expand All @@ -517,7 +518,7 @@ def bioinfo_doc(
results_md,
ctx.obj["api_user"],
ctx.obj["api_password"],
email_psswd,
email_pass,
)
new_doc.create_documentation()

Expand Down Expand Up @@ -564,6 +565,7 @@ def bioinfo_doc(
default=None,
help="Tsv output path + filename with archive stats and info",
)
@click.pass_context
def archive(
ctx,
service_id,
Expand Down
59 changes: 44 additions & 15 deletions bu_isciii/bioinfo_doc.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,34 @@ def create_structure(self):
return

def post_delivery_info(self):
delivery_notes = bu_isciii.utils.ask_for_some_text(
msg="Write some delivery notes:"
)
if bu_isciii.utils.prompt_yn_question(
msg="Do you wish to provide a text file for delivery notes?", dflt=False
):
for i in range(3, -1, -1):
self.provided_txt = bu_isciii.utils.prompt_path(
msg="Write the path to the file with RAW text as delivery notes"
)
if not os.path.isfile(os.path.expanduser(self.provided_txt)):
stderr.print(f"Provided file doesn't exist. Attempts left: {i}")
else:
stderr.print(f"File selected: {self.provided_txt}")
break
else:
stderr.print("No more attempts. Delivery notes will be given by prompt")
self.provided_txt = None
else:
self.provided_txt = None

if self.provided_txt:
with open(os.path.expanduser(self.provided_txt)) as f:
self.delivery_notes = " ".join([x.strip() for x in f.readlines()])
else:
self.delivery_notes = bu_isciii.utils.ask_for_some_text(
msg="Write some delivery notes:"
)
delivery_dict = {
"resolution_number": self.resolution_id,
"delivery_notes": delivery_notes,
"delivery_notes": self.delivery_notes,
}

# How json should be fully formatted:
Expand Down Expand Up @@ -568,9 +589,15 @@ def email_creation(self):
if bu_isciii.utils.prompt_yn_question(
"Do you want to add some delivery notes to the e-mail?", dflt=False
):
email_data["email_notes"] = bu_isciii.utils.ask_for_some_text(
msg="Write email notes"
)
if self.provided_txt:
if bu_isciii.utils.prompt_yn_question(
f"Do you want to use notes from {self.provided_txt}?", dflt=False
):
email_data["email_notes"] = self.delivery_notes
else:
email_data["email_notes"] = bu_isciii.utils.ask_for_some_text(
msg="Write email notes"
)

email_data["user_data"] = self.resolution_info["service_user_id"]
email_data["service_id"] = self.service_name.split("_", 5)[0]
Expand Down Expand Up @@ -617,18 +644,21 @@ def send_email(self, html_text, results_pdf_file):
+ self.service_name.split("_", 5)[2]
)
if bu_isciii.utils.prompt_yn_question(
"Do you want to add any other sender? appart from "
+ self.resolution_info["service_user_id"]["email"],
"Do you want to add any other sender? apart from %s. Note: %s is the default CC."
% (self.resolution_info["service_user_id"]["email"], msg["CC"].rstrip(";")),
dflt=False,
):
stderr.print(
"[red] Write emails to be added in semicolon separated format: bioinformatica@isciii.es;icuesta@isciii.es"
"[red] Write emails to be added in semicolon separated format: icuesta@isciii.es;user2@isciii.es"
)
msg["CC"] = bu_isciii.utils.ask_for_some_text(msg="E-mails:")
rcpt = msg["CC"].split(";") + [msg["To"]]
cc_address = bu_isciii.utils.ask_for_some_text(msg="E-mails:")
else:
rcpt = self.resolution_info["service_user_id"]["email"]

cc_address = str()
if cc_address:
msg["CC"] = str("[email protected];" + str(cc_address))
else:
msg["CC"] = "[email protected]"
rcpt = msg["CC"].split(";") + [msg["To"]]
html = MIMEText(html_text, "html")
msg.attach(html)
with open(results_pdf_file, "rb") as f:
Expand All @@ -639,7 +669,6 @@ def send_email(self, html_text, results_pdf_file):
filename=str(os.path.basename(results_pdf_file)),
)
msg.attach(attach)

server.sendmail(
email_host_user,
rcpt,
Expand Down
17 changes: 17 additions & 0 deletions bu_isciii/templates/services.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,22 @@
"last_folder":"REFERENCES",
"delivery_md": "",
"results_md": ""
},
"blast_nt": {
"label": "",
"template": "blast_nt",
"url": "",
"order": 1,
"begin": "",
"end": "",
"description": "",
"clean": {
"folders":[],
"files":[]
},
"no_copy": ["RAW", "TMP"],
"last_folder":"REFERENCES",
"delivery_md": "",
"results_md": ""
}
}
Loading