Beispiel #1
0
 def load_template(self):
     """ Load an existing config file or use the packaged examples"""
     if functions.main_is_frozen():
         self._configpath = os.environ['ALLUSERSPROFILE'] + '\\BigBrotherBot\\'
     else:
         self._configpath = 'b3\\'
     if self._set_parser == 'bfbc2':
         _dflttemplate = self._configpath + 'conf\\b3.bfbc2_example.xml'
     elif self._set_parser == 'moh':
         _dflttemplate = self._configpath + 'conf\\b3.moh_example.xml'
     else:
         _dflttemplate = self._configpath + 'conf\\b3.distribution.xml'
     if self._template != '':
         # means we just backed-up an old config with the same name
         _result = self.raw_default("Do you want to use the values from the backed-up config (%s)?"
                                    %(self._template), "yes")
         if _result != 'yes':
             self._template = self.raw_default("Load values from an existing configfile", _dflttemplate)
     else:
         self._template = self.raw_default("Load values from an existing configfile", _dflttemplate)
     self._template = self.getAbsolutePath(self._template)
     self.tree = ElementTree()
     try:
         self.tree.parse(self._template)
         return True
     except Exception, msg:
         #self.add_buffer('Could not parse xml file: %s\n' % msg)
         # backed up config file must be corrupt or not completed last setup, reset it to the default
         self.add_buffer('Your previous config file was either empty, corrupt or not finished.\
          Suggest we load the default...\n')
         self._template = ''
         return False
Beispiel #2
0
    def load_template(self):
        """ Load an existing config file or use the packaged examples"""
        if os.path.exists("b3/conf"):
            self._configpath = "b3/"
        # perhaps setup is executed directly
        elif os.path.exists("conf/"):
            self._configpath = ""
        elif functions.main_is_frozen():
            self._configpath = os.environ["ALLUSERSPROFILE"] + "/BigBrotherBot/"
        else:
            self._configpath = (
                self.raw_default("Could not locate the config folder, please provide the full path (using /)").rstrip(
                    "/"
                )
                + "/"
            )

        # load the template based on the parser the user just chose
        _dflttemplate = self._configpath + "conf/templates/b3." + self._set_parser + ".tpl"
        self._templatevar = "template"
        if not os.path.exists(_dflttemplate):
            _dflttemplate = self._configpath + "conf/b3.distribution.xml"
            self._templatevar = "distribution"

        if self._template != "":
            # means we just backed-up an old config with the same name
            _result = self.raw_default(
                "Do you want to use the values from the backed-up config (%s)?" % (self._template), "yes"
            )
            if _result != "yes":
                self._template = self.raw_default("Load values from a template", _dflttemplate)
            else:
                self._templatevar = "backup"
        else:
            self._template = self.raw_default("Load values from a template", _dflttemplate)

        self._template = self.getAbsolutePath(self._template)
        self.tree = ElementTree()
        try:
            self.tree.parse(self._template)
            return True
        except Exception, msg:
            self.add_buffer("Could not parse xml file: %s\n" % msg)
            # backed up config file must be corrupt or not completed last setup, reset it to the default
            self.add_buffer(
                "Your previous config file was either empty, corrupt or not finished.\
             I Suggest we load the default...\n"
            )
            self._template = ""
            return False
Beispiel #3
0
    def load_template(self):
        """ Load an existing config file or use the packaged examples"""
        if os.path.exists('b3/conf'):
            self._configpath = 'b3/'
        # perhaps setup is executed directly
        elif os.path.exists('conf/'):
            self._configpath = ''
        elif functions.main_is_frozen():
            self._configpath = os.environ['ALLUSERSPROFILE'] + '/BigBrotherBot/'
        else:
            self._configpath = self.raw_default(
                "Could not locate the config folder, please provide the full path (using /)"
            ).rstrip('/') + '/'

        # load the template based on the parser the user just chose
        _dflttemplate = self._configpath + 'conf/templates/b3.' + self._set_parser + '.tpl'
        self._templatevar = 'template'
        if not os.path.exists(_dflttemplate):
            _dflttemplate = self._configpath + 'conf/b3.distribution.xml'
            self._templatevar = 'distribution'

        if self._template != '':
            # means we just backed-up an old config with the same name
            _result = self.raw_default(
                "Do you want to use the values from the backed-up config (%s)?"
                % (self._template), "yes")
            if _result != 'yes':
                self._template = self.raw_default(
                    "Load values from a template", _dflttemplate)
            else:
                self._templatevar = 'backup'
        else:
            self._template = self.raw_default("Load values from a template",
                                              _dflttemplate)

        self._template = self.getAbsolutePath(self._template)
        self.tree = ElementTree()
        try:
            self.tree.parse(self._template)
            return True
        except Exception, msg:
            self.add_buffer('Could not parse xml file: %s\n' % msg)
            # backed up config file must be corrupt or not completed last setup, reset it to the default
            self.add_buffer(
                'Your previous config file was either empty, corrupt or not finished.\
             I Suggest we load the default...\n')
            self._template = ''
            return False
Beispiel #4
0
    def load_template(self):
        """ Load an existing config file or use the packaged examples"""
        if os.path.exists('b3/conf'):
            self._configpath = 'b3/'
        # perhaps setup is executed directly
        elif os.path.exists('conf/'):
            self._configpath = ''
        elif functions.main_is_frozen():
            self._configpath = os.environ['ALLUSERSPROFILE'] + '/BigBrotherBot/'
        else:
            self._configpath = self.raw_default(
                "Could not locate the config folder, please provide the full path (using /)").rstrip('/') + '/'

        # load the template based on the parser the user just chose
        _dflttemplate = self._configpath + 'conf/templates/b3.' + self._set_parser + '.tpl'
        self._templatevar = 'template'
        if not os.path.exists(_dflttemplate):
            _dflttemplate = self._configpath + 'conf/b3.distribution.xml'
            self._templatevar = 'distribution'

        if self._template != '':
            # means we just backed-up an old config with the same name
            _result = self.raw_default("Do you want to use the values from the backed-up config (%s)?"
                                       % (self._template), "yes")
            if _result != 'yes':
                self._template = self.raw_default("Load values from a template", _dflttemplate)
            else:
                self._templatevar = 'backup'
        else:
            self._template = self.raw_default("Load values from a template", _dflttemplate)

        self._template = self.getAbsolutePath(self._template)
        self.tree = ElementTree()
        try:
            self.tree.parse(self._template)
            return True
        except Exception, msg:
            self.add_buffer('Could not parse xml file: %s\n' % msg)
            # backed up config file must be corrupt or not completed last setup, reset it to the default
            self.add_buffer('Your previous config file was either empty, corrupt or not finished.\
             I Suggest we load the default...\n')
            self._template = ''
            return False
Beispiel #5
0
 def getB3Path(self):
     if main_is_frozen():
         # which happens when running from the py2exe build
         return os.path.dirname(sys.executable)
     return ""
Beispiel #6
0
 def getB3Path(self):
     if functions.main_is_frozen():
         # which happens when running from the py2exe build
         return os.path.dirname(sys.executable)
     return ""