def __init__(self): super(ComicStreamerConfig, self).__init__() self.csfolder = AppFolders.settings() # make sure folder exisits if not os.path.exists(self.csfolder): os.makedirs(self.csfolder) # set up initial values self.filename = os.path.join(self.csfolder, "comicstreamer") if platform.system() == "Windows": self.filename += ".ini" else: #if platform.system() == "Darwin": self.filename += ".conf" self.configspec = io.StringIO(ComicStreamerConfig.configspec) self.encoding = "UTF8" # since some stuff in the configobj has to happen during object initialization, # use a temporary delegate, and them merge it into self tmp = ConfigObj(self.filename, configspec=self.configspec, encoding=self.encoding) validator = Validator() tmp.validate(validator, copy=True) if tmp['format.ebook']['calibre'] == '': if platform.system() == "Darwin": calibre = '/Applications/calibre.app/Contents/MacOS/ebook-convert' if os.path.isfile(calibre): tmp['format.ebook']['calibre'] = calibre # set up the install ID if tmp['general']['install_id'] == '': tmp['general']['install_id'] = uuid.uuid4().hex #set up the cookie secret if tmp['security']['cookie_secret'] == '': tmp['security']['cookie_secret'] = base64.b64encode( uuid.uuid4().bytes + uuid.uuid4().bytes) # normalize the folder list tmp['general']['folder_list'] = [ os.path.abspath(os.path.normpath(unicode(a))) for a in tmp['general']['folder_list'] ] tmp['database.mysql']['password'] = utils.encode( tmp['general']['install_id'], 'comic') self.merge(tmp) if not os.path.exists(self.filename): self.write()
def __init__(self): super(ComicStreamerConfig, self).__init__() self.csfolder = AppFolders.settings() # make sure folder exisits if not os.path.exists( self.csfolder ): os.makedirs( self.csfolder ) # set up initial values self.filename = os.path.join(self.csfolder, "comicstreamer") if platform.system() == "Windows": self.filename += ".ini" else: #if platform.system() == "Darwin": self.filename += ".conf" self.configspec=io.StringIO(ComicStreamerConfig.configspec) self.encoding="UTF8" # since some stuff in the configobj has to happen during object initialization, # use a temporary delegate, and them merge it into self tmp = ConfigObj(self.filename, configspec=self.configspec, encoding=self.encoding) validator = Validator() tmp.validate(validator, copy=True) if tmp['format.ebook']['calibre'] == '': if platform.system() == "Darwin": calibre = '/Applications/calibre.app/Contents/MacOS/ebook-convert' if os.path.isfile(calibre): tmp['format.ebook']['calibre'] = calibre # set up the install ID if tmp['general']['install_id'] == '': tmp['general']['install_id'] = uuid.uuid4().hex #set up the cookie secret if tmp['security']['cookie_secret'] == '': tmp['security']['cookie_secret'] = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes) # normalize the folder list tmp['general']['folder_list'] = [os.path.abspath(os.path.normpath(unicode(a))) for a in tmp['general']['folder_list']] tmp['database.mysql']['password'] = utils.encode(tmp['general']['install_id'],'comic') self.merge(tmp) if not os.path.exists( self.filename ): self.write()