Ejemplo n.º 1
0
import smtplib
from XmlManager import XmlManager

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from LogManager import Log
#### Initializations ####
# Initializing logging
logger = Log.initialize('MailManager')


def send(message, status):
    SMTP_HOST = XmlManager.primaryConfig["smtpHost"]
    SMTP_PORT = XmlManager.primaryConfig["smtpPort"]
    DEBUG_STATUS = False
    SENDER = XmlManager.primaryConfig["JarvisEmail"]
    RECEIVER = XmlManager.primaryConfig["PrimaryCustEmail"]
    PASSWORD = XmlManager.primaryConfig["JarvisPasscode"]
    SUBJECT = XmlManager.primaryConfig["NotificationEmailSubject"]
    try:
        # creates SMTP session
        s = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
        # start TLS for security
        s.starttls()
        s.ehlo()
        # Switch to enable / disable debugging
        s.set_debuglevel(DEBUG_STATUS)
        # Authentication
        s.login(SENDER, PASSWORD)

        msg = MIMEMultipart('alternative')
Ejemplo n.º 2
0
from string import ascii_uppercase
from XmlManager import XmlManager
from datetime import datetime
import MailManager as mail
import os
import shutil
import sys
from LogManager import Log
#### Initializations ####
# Initializing logging
logger = Log.initialize('DriveManager')

path_seperator = "\\"


def get_usb_drive(identifier_file_name):
    platform_name = get_platform()
    if platform_name is not "Windows":
        path_seperator = "/"
    for drive in ascii_uppercase:
        fullpath = drive + ":\\" + identifier_file_name
        if os.path.exists(fullpath):
            return drive + ":\\"
    return ""


def getFreeSpaceOnBackupDrive(driveLetter):
    abc = shutil.disk_usage(driveLetter)
    return abc.free

Ejemplo n.º 3
0
import xml.etree.ElementTree as ET
from Crypt import Crypt
from LogManager import Log
#### Initializations ####
# Initializing logging
logger = Log.initialize('XmlManager')


class XmlManager:
    @classmethod
    def MainConfig(cls):
        logger.info("Initializing Xml configuration")
        try:
            configurationDetails = ET.parse(
                'configuration.xml'
            )  #This file may not exist, introduce fatal error
        except Exception as err:
            logger.critical("Cannot parse configuration.xml")
        ConfigDict = {}

        if configurationDetails is not None:
            #Checking the log level
            logger.info("configuration.xml parsed successfully")
            ConfigDict["loggingLevel"] = configurationDetails.find(
                'loggingLevel').text
            if ConfigDict["loggingLevel"] != "DEBUG":
                level = Log.getLogLevel(ConfigDict["loggingLevel"])
                Log.loggingLevel = level
                logger.setLevel(level)
                for handler in logger.handlers:
                    handler.setLevel(level)
Ejemplo n.º 4
0
# Handling imports
import DriveManager as dm       # Takes care of drive in which backup is supposed to written
import BackupDataManager as bdm # Takes care of data which is supposed to be backed up
from XmlManager import XmlManager
import MailManager as mail
from LogManager import Log

#### Initializations ####
# Initializing Xml configuration management
XmlManager.primaryConfig = XmlManager.MainConfig()
XmlManager.paths = XmlManager.PathManager()

# Initializing logging
logger = Log.initialize('BackupEngine')

#### Initializations ####

# Getting Identified filename
logger.debug("Fetching the name of the identifier file name from xml configuration")
identifier_file_name=XmlManager.primaryConfig["IdentifierFile"]
logger.debug("Fetched the name of the identifier file name from xml configuration")
# Checking all drives for identifier file
logger.debug("Checking all drives for identifier file")
drive = dm.get_usb_drive(identifier_file_name)

if drive!="":
    # Backup drive successfully connected / Identifier file found
    logger.info("Backup drive successfully connected")
    logger.debug("Checking free space in backup drive")
    # Checking the free space available on the backup drive in bytes
    free_space_backup_drive = dm.getFreeSpaceOnBackupDrive(drive)
Ejemplo n.º 5
0
import os
from XmlManager import XmlManager
import MailManager as mail
from LogManager import Log

#### Initializations ####
# Initializing logging
logger = Log.initialize('BackupDataManager')


# Include a check for timeout and directory tree size depth for huge folders
def get_size(start_path):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(start_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            # skip if it is symbolic link
            if not os.path.islink(fp):
                total_size += os.path.getsize(fp)

    return total_size


def write_to_text_file(filename, data):
    try:
        handle = open(filename, "a+")
        handle.write(data)
    except FileNotFoundError:
        logger.error("File " + filename + " not found")
        if XmlManager.primaryConfig["EmailNotifications"] == "Enabled":
            # Email sending is enabled, send email