def test_set_config(self): self.write_good_file() self.config['new_key'] = 'new_value' write_config(self.config, self.config_file_path) # re-read the config file self.config2 = read_config(self.config_file_path) # Check value. self.assertEqual('new_value', self.config2.get('new_key'))
def _get_encoding(self): """Return the repository encoding in a normalized format (lowercase and replace - by _).""" # For backward compatibility, look into the database and fallback to # the rdiffweb config file in the repo. encoding = self._get_attr('encoding') if encoding: return encodings.search_function(encoding.lower()) # Read encoding value from obsolete config file. try: conf_file = os.path.join(self._data_path, b'rdiffweb') if os.access(conf_file, os.F_OK) and os.path.isfile(conf_file): config = read_config(conf_file) encoding = config.get('encoding') if encoding: return encodings.search_function(encoding) except: logger.exception("fail to get repo encoding from file") # Fallback to default encoding. return encodings.search_function(DEFAULT_REPO_ENCODING)
def start(): """Start rdiffweb deamon.""" # Parse command line options args = {} opts = getopt.getopt(sys.argv[1:], 'vdrf:', [ 'debug', 'log-file=', 'log-access-file=', 'config=', ])[0] for option, value in opts: if option in ['-d', '--debug']: args['debug'] = True elif option in ['--log-file']: args['log_file'] = value elif option in ['--log-access-file']: args['log_access_file'] = value elif option in ['-f', '--config']: args['config'] = value # Open config file before opening the apps. configfile = args.get('config', '/etc/rdiffweb/rdw.conf') cfg = read_config(configfile) log_file = args.get('log_file', None) or cfg.get('logfile', False) log_access_file = args.get('log_access_file', None) or cfg.get( 'logaccessfile', None) if args.get('debug', False): environment = 'development' log_level = "DEBUG" else: environment = cfg.get('environment', 'production') log_level = cfg.get('loglevel', 'INFO') # Configure logging setup_logging(log_file=log_file, log_access_file=log_access_file, level=log_level) # Create App. app = rdw_app.RdiffwebApp(cfg) # Get configuration serverHost = nativestr(cfg.get("serverhost", "127.0.0.1")) serverPort = int(cfg.get("serverport", "8080")) # Get SSL configuration (if any) sslCertificate = cfg.get("sslcertificate") sslPrivateKey = cfg.get("sslprivatekey") global_config = cherrypy._cpconfig.environments.get(environment, {}) global_config.update({ 'server.socket_host': serverHost, 'server.socket_port': serverPort, 'server.log_file': log_file, 'server.ssl_certificate': sslCertificate, 'server.ssl_private_key': sslPrivateKey, # Set maximum POST size to 2MiB, for security. 'server.max_request_body_size': 2097152, 'server.environment': environment, }) cherrypy.config.update(global_config) # Add a custom signal handler cherrypy.engine.signal_handler.handlers['SIGUSR2'] = debug_dump_mem cherrypy.engine.signal_handler.handlers['SIGABRT'] = debug_dump_thread # Start deamons RemoveOlder(cherrypy.engine, app).subscribe() NotificationPlugin(cherrypy.engine, app).subscribe() # Start web server cherrypy.quickstart(app) # Log startup logger.info("STOP")
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. ''' Created on Mar. 3, 2019 @author: Patrik Dufresne <*****@*****.**> ''' from __future__ import unicode_literals from rdiffweb.core.config import read_config from rdiffweb.rdw_app import RdiffwebApp import cherrypy import os if __name__.startswith("uwsgi"): # Read config file configfile = os.environ.get('RDIFFWEB_CONFIG', '/etc/rdiffweb/rdw.conf') cfg = read_config(configfile) # Create application cherrypy.config.update({'engine.autoreload.on': False}) cherrypy.server.unsubscribe() cherrypy.engine.start() wsgiapp = cherrypy.tree.mount(RdiffwebApp(cfg))
def write_bad_file(self, bad_setting_num): self.write_good_file() f = open(self.config_file_path, "w") f.write(self.bad_config_texts[bad_setting_num]) f.close() self.config = read_config(self.config_file_path)
def write_good_file(self): f = open(self.config_file_path, "w") f.write(self.good_config_text) f.close() self.config = read_config(self.config_file_path)