예제 #1
0
 def get_set(self, settings_file):
     """Read in the settings file and configure CannedPostResponder 
     accordingly."""
     settings = io_cpr.get_settings(settings_file)
     for setting in settings_vars:
         try:
             setattr(self, setting, settings[setting])
         except KeyError:
             logging.error("%s not present in settings file.  Terminating.",
                           setting)
             terminate(1)
     try:
         ip = io_cpr.Instruction_Parser(instructions_file)
         self.instructions = [Instruction(i[0], i[1], i[2]) for i in ip]
     except io_cpr.parseError as err:
         logging.error("Could not parse instructions file.  Terminating")
         terminate(1)
     except IOError as err:
         if err.errno == 2:
             # file doesn't exist
             logging.error("Instructions file not found.  Terminating.")
             terminate(1)
     self.messages = {}
     for instruction in self.instructions:
         message_file = path + instruction.filename
         try:
             self.messages[instruction.filename] = \
                 open(message_file, 'r').read().rstrip()
         except IOError as err:
             if err.errno == 2:
                 # file doesn't exist
                 logging.error(("%s file is nonexistent or unreadable.  "
                                "Terminating."), message_file)
                 terminate(1)
     if os.path.exists(latest_file):
         latest_text = open(latest_file, "r").read()
     else:
         latest_text = ""
     self.latest = Latest(latest_text)
     if os.path.exists(alreadies_file):
         alreadies_text = open(alreadies_file, "r").read()
     else:
         alreadies_text = ""
     self.alreadies = Alreadies(alreadies_text)
     self.smtp = io_cpr.CPR_SMTP(host=self.smtp_server, port=self.smtp_port)
     self.email_on = False
     if self.email:
         try:
             self.smtp.login(self.email, self.email_password)
             self.smtp.set_recipients(self.recipients)
             self.email_on = True
         except Exception as err:
             logging.error("Could not log into email as %s\nError: %s",
                           self.email, str(err))
             terminate(1)
     self.user_agent = ('CannedPostResponder %s '
                        'operated by %s '
                        'writtn by %s' %
                        (__version__, self.proprietor, __author__))
예제 #2
0
                          'of CannedPostResponder if there is one'))
parser.add_argument('--resume',
                    action='store_true',
                    help=('resume the currently running instance '
                          'of CannedPostResponder if there is one'))
parser.add_argument('--kill',
                    action='store_true',
                    help=('kill the currently running instance '
                          'of CannedPostResponder if there is one'))
parser.add_argument('--status',
                    action='store_true',
                    help=('report whether or not an instance of '
                          'CannedPostResponder is currently running'))

args = parser.parse_args()
settings = io_cpr.get_settings(cannedpostresponder.settings_file)
argdic = vars(args)
change_made = False
for key in argdic:
    if argdic[key]:
        adder = re.compile("add_(?P<variable>.*)")
        deleter = re.compile("del_(?P<variable>.*)")
        addmatch = adder.match(key)
        delmatch = deleter.match(key)
        varname = ""
        if addmatch:
            # anything appendable begins with add_<variable>
            varname = addmatch.group("variable")
            to_add = argdic[key]
            if varname in settings:
                settings[varname].extend(to_add)
예제 #3
0
                            'isn\'t already one'))
parser.add_argument('--suspend', action = 'store_true',
                    help = ('suspend the currently running instance '
                            'of CannedPostResponder if there is one'))
parser.add_argument('--resume', action = 'store_true',
                    help = ('resume the currently running instance '
                            'of CannedPostResponder if there is one'))
parser.add_argument('--kill', action = 'store_true',
                    help = ('kill the currently running instance '
                            'of CannedPostResponder if there is one'))
parser.add_argument('--status', action = 'store_true',
                    help = ('report whether or not an instance of '
                            'CannedPostResponder is currently running'))

args = parser.parse_args()
settings = io_cpr.get_settings(cannedpostresponder.settings_file)
argdic = vars(args)
change_made = False
for key in argdic:
    if argdic[key]:
        adder = re.compile("add_(?P<variable>.*)")
        deleter = re.compile("del_(?P<variable>.*)")
        addmatch = adder.match(key)
        delmatch = deleter.match(key)
        varname = ""
        if addmatch:
            # anything appendable begins with add_<variable>
            varname = addmatch.group("variable")
            to_add = argdic[key]
            if varname in settings:
                settings[varname].extend(to_add)
 def get_set(self, settings_file):
     """Read in the settings file and configure CannedPostResponder 
     accordingly."""
     settings = io_cpr.get_settings(settings_file)
     for setting in settings_vars:
         try:
             setattr(self, setting, settings[setting])
         except KeyError:
             logging.error("%s not present in settings file.  Terminating.",
                           setting)
             terminate(1)
     try:
         ip = io_cpr.Instruction_Parser(instructions_file)
         self.instructions = [Instruction(i[0], i[1], i[2]) for 
                              i in ip]
     except io_cpr.parseError as err:
         logging.error("Could not parse instructions file.  Terminating")
         terminate(1)
     except IOError as err:
         if err.errno == 2:
             # file doesn't exist
             logging.error("Instructions file not found.  Terminating.")
             terminate(1)
     self.messages = {}
     for instruction in self.instructions:
         message_file = path + instruction.filename
         try:
             self.messages[instruction.filename] = \
                 open(message_file, 'r').read().rstrip()
         except IOError as err:
             if err.errno == 2:
                 # file doesn't exist
                 logging.error(("%s file is nonexistent or unreadable.  "
                                "Terminating."), 
                               message_file)
                 terminate(1)
     if os.path.exists(latest_file):
         latest_text = open(latest_file, "r").read()
     else:
         latest_text = ""
     self.latest = Latest(latest_text)
     if os.path.exists(alreadies_file):
         alreadies_text = open(alreadies_file, "r").read()
     else:
         alreadies_text = ""
     self.alreadies = Alreadies(alreadies_text)
     self.smtp = io_cpr.CPR_SMTP(host = self.smtp_server, 
                                 port = self.smtp_port)
     self.email_on = False
     if self.email:
         try:
             self.smtp.login(self.email, self.email_password)
             self.smtp.set_recipients(self.recipients)
             self.email_on = True
         except Exception as err:
             logging.error("Could not log into email as %s\nError: %s", 
                           self.email, str(err))
             terminate(1)
     self.user_agent = ('CannedPostResponder %s '
                        'operated by %s '
                        'writtn by %s' % (__version__, 
                                          self.proprietor, 
                                          __author__))