コード例 #1
0
    def test_sendmail_fired(self, SMTP_mock):
        # sendmail should fire only when testing is False
        smtp_instance = SMTP_mock.return_value
        emailer = messaging.Emailer(self.to, False)
        emailer.sendEmail(self.sub, self.body)
        self.assertTrue(smtp_instance.sendmail.called)

        smtp_instance.reset_mock()
        emailer.testing = True
        emailer.sendEmail(self.sub, self.body)
        self.assertFalse(smtp_instance.sendmail.called)
コード例 #2
0
    def test_email_msg_format(self, SMTP_mock):
        # should format the message correctly
        emailer = messaging.Emailer(self.to, False)
        emailer.sendEmail(self.sub, self.body)
        args = SMTP_mock.return_value.sendmail.call_args[0]

        self.assertEqual(args[0], emailer.fromAddress)
        self.assertEqual(args[1], [self.to])
        self.assertEqual(args[2], (
            'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: '
            '7bit\nSubject: test sub\nFrom: [email protected]\nTo: [email protected]\n\ntest body'
        ))
コード例 #3
0
 def test_quit(self, SMTP_mock):
     # should call quit on the server when it is finished
     emailer = messaging.Emailer(self.to, False)
     emailer.sendEmail(self.sub, self.body)
     self.assertTrue(SMTP_mock.return_value.quit.called)
コード例 #4
0
    def test_multiple_to_addresses(self, SMTP_mock):
        emailer = messaging.Emailer('[email protected];[email protected]')
        emailer.sendEmail(self.sub, self.body)
        args = SMTP_mock.return_value.sendmail.call_args[0]

        self.assertEqual(args[1], ['*****@*****.**', '*****@*****.**'])
コード例 #5
0
'''
Used to send diagnostic information to tech support. Including
unsubmitted report data to make sure that it doesn't get lost.
'''

import arcpy
from agrc import messaging

'''
GP Parameters:
0 - username: String
1 - unsubmittedReports: String (json array of report objects)
2 - platform: String
'''

# logger = logging.Logger() # having troubles with location of logs directory when run via Catalog
emailer = messaging.Emailer('*****@*****.**')
msg = ''

username = arcpy.GetParameterAsText(0)
msg += 'username: '******'\n'

unsubmittedReports = arcpy.GetParameterAsText(1)
msg += 'unsubmittedReports: ' + unsubmittedReports + '\n'

platform = arcpy.GetParameterAsText(2)
msg += 'platform: ' + platform + '\n'

emailer.sendEmail('Roadkill Diagnostics Report for ' + username, msg)
コード例 #6
0
    'NAIP2016_Color1Meter_4Band': ('state-of-utah-naip-2016-rgb', 'jpeg'),
    'NAIP2016_Color1Meter_4Band_NRG': ('state-of-utah-naip-2016-nrg', 'jpeg'),
    'Topo': ('state-of-utah-topo-tiles/Topo', 'jpeg'),
    'AddressPoints':
    ('state-of-utah-pyramid-tiles-address-points/AddressPoints', 'png'),
    'Hillshade': ('state-of-utah-pyramid-tiles-hillshade/Hillshade', 'jpeg')
}

try:
    cache_folder_name = argv[1]
except:
    cache_folder_name = raw_input(
        'Cache Folder Name (e.g. BaseMaps_Terrain): ')

new_folder = os.path.join(AGS_CACHE_DIR, cache_folder_name + '_GCS')
emailer = messaging.Emailer('*****@*****.**', testing=False)
base_folder = os.path.join(AGS_CACHE_DIR, cache_folder_name,
                           r'Layers\_alllayers')
bucket, image_type = CACHES[cache_folder_name]
content_type = 'image/{}'.format(image_type)
script_folder = os.path.dirname(os.path.abspath(__file__))

try:
    print('deleting old *_GCS folder')
    shutil.rmtree(new_folder)
except:
    pass


def process_level(level):
    try:
コード例 #7
0
 def __init__(self):
     self.start_time = time.time()
     self.logger = logging.Logger()
     self.emailer = messaging.Emailer(settings.NOTIFICATION_EMAILS,
                                      testing=not settings.SEND_EMAILS)
コード例 #8
0
import arcpy
from agrc import logging
from agrc import messaging
from agrc import arcpy_helpers
import settings

fgdb = r'\\172.16.17.53\ArcGISServer\data\SGID10.gdb'
sde = r'.\database_connections\SGID10.sde'

# get parameters
fClass = arcpy.GetParameterAsText(0)
local = fgdb + '\\' + fClass

logger = logging.Logger()
emailer = messaging.Emailer(settings.NOTIFICATION_EMAILS)

try:
    logger.logMsg('Finding sde feature class')
    fClass_SDE = arcpy_helpers.FindFeatureClassInSDE(fClass, sde)

    logger.logMsg('Deleting local data, if it exists already')
    arcpy_helpers.DeleteIfExists([local])

    logger.logMsg('Coping new data to local fgdb')
    arcpy.Copy_management(fClass_SDE, local)

except arcpy.ExecuteError as e:
    logger.logMsg('arcpy.ExecuteError')
    logger.logError()
    logger.logGPMsg()
コード例 #9
0
    def sendSuccessEmail(self, fc):
        body = 'The {} feature class was updated and all associated locators were rebuilt.'.format(fc)
        self.emailer.sendEmail('{}-related locators were rebuilt'.format(fc),
                               body)

    def runWithTryCatch(self):
        try:
            self.roads()
            self.address_points()
            self.logger.logMsg('\nScript completed successfully!')
        except arcpy.ExecuteError:
            self.logger.logMsg('arcpy.ExecuteError')
            self.logger.logError()
            self.logger.logGPMsg()
            self.emailer.sendEmail(
                self.logger.scriptName + ' - arcpy.ExecuteError',
                self.logger.log)
        except Exception:
            self.logger.logError()
            self.emailer.sendEmail(
                self.logger.scriptName + ' - Python Error',
                self.logger.log)
        finally:
            self.logger.writeLogToFile()

if __name__ == "__main__":
    Runner(
        logging.Logger(),
        messaging.Emailer(settings.LOCATOR_NOTIFICATION_EMAILS,
                          testing=not settings.SEND_EMAILS)).runWithTryCatch()