<commit_before>#! /usr/bin/env python

# ------------------------------------------------------------------------------
# Script which adds new users fram google spreadsheet into the the cgds
# user table.  The following properties must be specified in portal.properties:
#
# db.name
# db.user
# db.password
# db.host
# google.id
# google.pw
# users.spreadsheet
# users.worksheet
#
# The script considers all users in the google spreadsheet
# that have an "APPROVED" value in the "Status (APPROVED or BLANK)" column.  If that
# user does not exist in the user table of the cgds database, the user will be added
# to both the user table and authority table.  In addition, a confirmation email will
# be sent to the user notifying them of their acct activation.
#
# ------------------------------------------------------------------------------
# imports
import os
import sys
import time
import getopt
import MySQLdb

import smtplib
import gdata.docs.client
import gdata.docs.service
import gdata.spreadsheet.service

from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders

# ------------------------------------------------------------------------------
# globals

# some file descriptors
ERROR_FILE = sys.stderr
OUTPUT_FILE = sys.stdout

# fields in portal.properties
CGDS_DATABASE_HOST = 'db.host'
CGDS_DATABASE_NAME = 'db.portal_db_name'
CGDS_DATABASE_USER = 'db.user'
CGDS_DATABASE_PW = '<PASSWORD>'
GOOGLE_ID = 'google.id'
GOOGLE_PW = '<PASSWORD>'
CGDS_USERS_SPREADSHEET = 'users.spreadsheet'
CGDS_USERS_WORKSHEET = 'users.worksheet'

# Google spreadsheet name - used as keys to email subjects/body below
GDAC_USER_SPREADSHEET = 'Request Access to the cBio GDAC Cancer Genomics Portal'
SU2C_USER_SPREADSHEET = 'Request Access to the cBio SU2C Cancer Genomics Portal'
PROSTATE_USER_SPREADSHEET = 'Request Access to the cBio Prostate Cancer Genomics Portal'
GLIOMA_USER_SPREADSHEET = 'Request Access to the cBio Glioma Cancer Genomics Portal'
ACC_USER_SPREADSHEET = 'Request Access to the cBio ACC Cancer Genomics Portal'
TARGET_USER_SPREADSHEET = 'Request Access to the cBio TARGET Cancer Genomics Portal'
MSKCC_USER_SPREADSHEET = 'Request Access to the cBio MSKCC Cancer Genomics Portal'

# portal name (these should correspond to what is in property file of the respective portal)
PORTAL_NAME = { GDAC_USER_SPREADSHEET : "gdac-portal",
                PROSTATE_USER_SPREADSHEET : "prostate-portal",
                GLIOMA_USER_SPREADSHEET : "glioma-portal",
                ACC_USER_SPREADSHEET : "acc-portal",
                SU2C_USER_SPREADSHEET : "su2c-portal",
                TARGET_USER_SPREADSHEET : "target-portal",
                MSKCC_USER_SPREADSHEET : "mskcc-portal" }

# a ref to the google spreadsheet client - used for all i/o to google spreadsheet
GOOGLE_SPREADSHEET_CLIENT = gdata.spreadsheet.service.SpreadsheetsService()

# column constants on google spreadsheet
FULLNAME_KEY = "fullname"
INST_EMAIL_KEY = "institutionalemailaddress"
MSKCC_EMAIL_KEY = "mskccemailaddress"
OPENID_EMAIL_KEY = "googleoropenidaddress"
STATUS_KEY = "statusapprovedorblank"
AUTHORITIES_KEY = "authoritiesalloralltcgaandorsemicolondelimitedcancerstudylist"
LAB_PI_KEY = "labpi"
TIMESTAMP_KEY = "timestamp"

# possible values in status column
STATUS_APPROVED = "APPROVED"

DEFAULT_AUTHORITIES = "PUBLIC;EXTENDED;MSKPUB"

# consts used in email
MSKCC_EMAIL_SUFFIX = "@mskcc.org"
SMTP_SERVER = "cbio.mskcc.org"
MESSAGE_FROM = "<EMAIL>.<EMAIL>"
MESSAGE_BCC = ["<EMAIL>", "<EMAIL>", "<EMAIL>"]
MESSAGE_SUBJECT = { GDAC_USER_SPREADSHEET : "You have been granted access to the private instance of cBioPortal",
                    PROSTATE_USER_SPREADSHEET : "cBioPortal for Prostate Cancer Access",
                    GLIOMA_USER_SPREADSHEET : "cBioPortal for Glioma Access",
                    ACC_USER_SPREADSHEET : "cBioPortal for ACC Access",
                    SU2C_USER_SPREADSHEET : "cBioPortal for SU2C Access",
                    TARGET_USER_SPREADSHEET : "cBioPortal for NCI-TARGET",
                    MSKCC_USER_SPREADSHEET : "cBioPortal for MSKCC" }
GDAC_MESSAGE_BODY = """Thank you for your interest in the private instance of cBioPortal. We have granted you access. You can login at http://cbioportal.org/gdac-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary and subject to change. This data is only available to researchers funded through TCGA or involved in the TCGA Disease and Analysis Working Groups.
"""

SU2C_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for SU2C. We have granted you access. You can login at http://cbioportal.org/su2c-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

PROSTATE_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for Prostate. We have granted you access. You can login at http://cbioportal.org/prostate-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

GLIOMA_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for Glioma. We have granted you access. You can login at http://cbioportal.org/glioma-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

ACC_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for ACC. We have granted you access. You can login at http://cbioportal.org/acc-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

TARGET_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for NCI-TARGET. We have granted you access. You can login at http://cbioportal.org/target-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

MSKCC_MESSAGE_BODY = """Thank you for your interest in the MSKCC instance of cBioPortal. We have granted you access. You can login at http://cbioportal.org/mskcc-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the data provided in this Portal are preliminary and subject to change. Access to the data in this portal is only available to authorized users at Memorial Sloan Kettering Cancer Center.
"""


MESSAGE_BODY = { GDAC_USER_SPREADSHEET : GDAC_MESSAGE_BODY,
                 PROSTATE_USER_SPREADSHEET : PROSTATE_MESSAGE_BODY,
                 GLIOMA_USER_SPREADSHEET : GLIOMA_MESSAGE_BODY,
                 ACC_USER_SPREADSHEET : ACC_MESSAGE_BODY,
                 SU2C_USER_SPREADSHEET : SU2C_MESSAGE_BODY,
                 TARGET_USER_SPREADSHEET : TARGET_MESSAGE_BODY,
                 MSKCC_USER_SPREADSHEET : MSKCC_MESSAGE_BODY }<commit_msg>Added support for triage portal<commit_after>#! /usr/bin/env python

# ------------------------------------------------------------------------------
# Script which adds new users fram google spreadsheet into the the cgds
# user table.  The following properties must be specified in portal.properties:
#
# db.name
# db.user
# db.password
# db.host
# google.id
# google.pw
# users.spreadsheet
# users.worksheet
#
# The script considers all users in the google spreadsheet
# that have an "APPROVED" value in the "Status (APPROVED or BLANK)" column.  If that
# user does not exist in the user table of the cgds database, the user will be added
# to both the user table and authority table.  In addition, a confirmation email will
# be sent to the user notifying them of their acct activation.
#
# ------------------------------------------------------------------------------
# imports
import os
import sys
import time
import getopt
import MySQLdb

import smtplib
import gdata.docs.client
import gdata.docs.service
import gdata.spreadsheet.service

from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders

# ------------------------------------------------------------------------------
# globals

# some file descriptors
ERROR_FILE = sys.stderr
OUTPUT_FILE = sys.stdout

# fields in portal.properties
CGDS_DATABASE_HOST = 'db.host'
CGDS_DATABASE_NAME = 'db.portal_db_name'
CGDS_DATABASE_USER = 'db.user'
CGDS_DATABASE_PW = '<PASSWORD>'
GOOGLE_ID = 'google.id'
GOOGLE_PW = '<PASSWORD>'
CGDS_USERS_SPREADSHEET = 'users.spreadsheet'
CGDS_USERS_WORKSHEET = 'users.worksheet'

# Google spreadsheet name - used as keys to email subjects/body below
GDAC_USER_SPREADSHEET = 'Request Access to the cBio GDAC Cancer Genomics Portal'
SU2C_USER_SPREADSHEET = 'Request Access to the cBio SU2C Cancer Genomics Portal'
PROSTATE_USER_SPREADSHEET = 'Request Access to the cBio Prostate Cancer Genomics Portal'
GLIOMA_USER_SPREADSHEET = 'Request Access to the cBio Glioma Cancer Genomics Portal'
ACC_USER_SPREADSHEET = 'Request Access to the cBio ACC Cancer Genomics Portal'
TARGET_USER_SPREADSHEET = 'Request Access to the cBio TARGET Cancer Genomics Portal'
MSKCC_USER_SPREADSHEET = 'Request Access to the cBio MSKCC Cancer Genomics Portal'
TRIAGE_USER_SPREADSHEET = 'Request Access to the cBio MSKCC (Triage) Cancer Genomics Portal'

# portal name (these should correspond to what is in property file of the respective portal)
PORTAL_NAME = { GDAC_USER_SPREADSHEET : "gdac-portal",
                PROSTATE_USER_SPREADSHEET : "prostate-portal",
                GLIOMA_USER_SPREADSHEET : "glioma-portal",
                ACC_USER_SPREADSHEET : "acc-portal",
                SU2C_USER_SPREADSHEET : "su2c-portal",
                TARGET_USER_SPREADSHEET : "target-portal",
                MSKCC_USER_SPREADSHEET : "mskcc-portal",
                TRIAGE_USER_SPREADSHEET : "triage-portal" }

# a ref to the google spreadsheet client - used for all i/o to google spreadsheet
GOOGLE_SPREADSHEET_CLIENT = gdata.spreadsheet.service.SpreadsheetsService()

# column constants on google spreadsheet
FULLNAME_KEY = "fullname"
INST_EMAIL_KEY = "institutionalemailaddress"
MSKCC_EMAIL_KEY = "mskccemailaddress"
OPENID_EMAIL_KEY = "googleoropenidaddress"
STATUS_KEY = "statusapprovedorblank"
AUTHORITIES_KEY = "authoritiesalloralltcgaandorsemicolondelimitedcancerstudylist"
LAB_PI_KEY = "labpi"
TIMESTAMP_KEY = "timestamp"

# possible values in status column
STATUS_APPROVED = "APPROVED"

DEFAULT_AUTHORITIES = "PUBLIC;EXTENDED;MSKPUB"

# consts used in email
MSKCC_EMAIL_SUFFIX = "@mskcc.org"
SMTP_SERVER = "cbio.mskcc.org"
MESSAGE_FROM = "<EMAIL>"
MESSAGE_BCC = ["<EMAIL>", "<EMAIL>", "<EMAIL>"]
MESSAGE_SUBJECT = { GDAC_USER_SPREADSHEET : "You have been granted access to the private instance of cBioPortal",
                    PROSTATE_USER_SPREADSHEET : "cBioPortal for Prostate Cancer Access",
                    GLIOMA_USER_SPREADSHEET : "cBioPortal for Glioma Access",
                    ACC_USER_SPREADSHEET : "cBioPortal for ACC Access",
                    SU2C_USER_SPREADSHEET : "cBioPortal for SU2C Access",
                    TARGET_USER_SPREADSHEET : "cBioPortal for NCI-TARGET",
                    MSKCC_USER_SPREADSHEET : "cBioPortal for MSKCC",
                    TRIAGE_USER_SPREADSHEET : "cBioPortal for MSKCC (Triage)" }
GDAC_MESSAGE_BODY = """Thank you for your interest in the private instance of cBioPortal. We have granted you access. You can login at http://cbioportal.org/gdac-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary and subject to change. This data is only available to researchers funded through TCGA or involved in the TCGA Disease and Analysis Working Groups.
"""

SU2C_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for SU2C. We have granted you access. You can login at http://cbioportal.org/su2c-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

PROSTATE_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for Prostate. We have granted you access. You can login at http://cbioportal.org/prostate-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

GLIOMA_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for Glioma. We have granted you access. You can login at http://cbioportal.org/glioma-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

ACC_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for ACC. We have granted you access. You can login at http://cbioportal.org/acc-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

TARGET_MESSAGE_BODY = """Thank you for your interest in the cBioPortal for NCI-TARGET. We have granted you access. You can login at http://cbioportal.org/target-portal/. Please let us know if you have any problems logging in.

Please keep in mind that the majority of the data provided in this Portal is preliminary, unpublished and subject to change.
"""

MSKCC_MESSAGE_BODY = """Thank you for your interest in the MSKCC instance of cBioPortal. We have granted you access. You can login at cbioportal.mskcc.org. Please let us know if you have any problems logging in.

Please keep in mind that the data provided in this Portal are preliminary and subject to change. Access to the data in this portal is only available to authorized users at Memorial Sloan Kettering Cancer Center.
"""

TRIAGE_MESSAGE_BODY = """Thank you for your interest in the MSKCC (triage)instance of cBioPortal. We have granted you access. You can login at cbioportal.triage.mskcc.org. Please let us know if you have any problems logging in.

Please keep in mind that the data provided in this Portal are preliminary and subject to change. Access to the data in this portal is only available to authorized users at Memorial Sloan Kettering Cancer Center.
"""


MESSAGE_BODY = { GDAC_USER_SPREADSHEET : GDAC_MESSAGE_BODY,
                 PROSTATE_USER_SPREADSHEET : PROSTATE_MESSAGE_BODY,


MESSAGE_BODY = { GDAC_USER_SPREADSHEET : GDAC_MESSAGE_BODY,
                 PROSTATE_USER_SPREADSHEET : PROSTATE_MESSAGE_BODY,
                 GLIOMA_USER_SPREADSHEET : GLIOMA_MESSAGE_BODY,
                 ACC_USER_SPREADSHEET : ACC_MESSAGE_BODY,
                 SU2C_USER_SPREADSHEET : SU2C_MESSAGE_BODY,
                 TARGET_USER_SPREADSHEET : TARGET_MESSAGE_BODY,
                 MSKCC_USER_SPREADSHEET : MSKCC_MESSAGE_BODY,
                 TRIAGE_USER_SPREADSHEET : TRIAGE_MESSAGE_BODY }
{'fraction_non_alphanumeric': 0.08856516694598428, 'fraction_numerical': 0.0014180739976795153, 'mean_word_length': 3.507553747821034, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3294314', 'n_tokens_mistral': 4727, 'n_tokens_neox': 4559, 'n_words': 1696}