def dump(): assert isinstance(application.options, OptionsCore), 'Invalid application options %s' % application.options if not application.options.writeConfigurations: return if not __debug__: print('Cannot dump configuration file if python is run with "-O" or "-OO" option', file=sys.stderr) sys.exit(1) try: context.activate(dumpAssembly()) try: loadPlugins() configFile = configurations_file_path() if os.path.isfile(configFile): with open(configFile, 'r') as f: config = load(f) else: config = {} context.open(aop.modulesIn('__plugin__.**'), config=config, included=True) try: if os.path.isfile(configFile): os.rename(configFile, configFile + '.bak') with open(configFile, 'w') as f: save(context.configurations(force=True), f) print('Created "%s" configuration file' % configFile) finally: context.deactivate() finally: context.deactivate() except SystemExit: raise except: print('-' * 150, file=sys.stderr) print('A problem occurred while dumping configurations', file=sys.stderr) traceback.print_exc(file=sys.stderr) print('-' * 150, file=sys.stderr)
def persistMarkers(used): ''' Persist the markers of the executed events''' assert isinstance(used, set), 'Invalid used %s' % used plen = len('__plugin__.') configs = {} for name, value in markers().items(): if name in used: group = 'current markers' else: group = 'unused markers' configs[name[plen:]] = Config(name, value, group) with open(distribution_file_path(), 'w') as f: save(configs, f)
def persistMarkers(): ''' Persist the markers of the executed events''' plen = len('__plugin__.') configs = {} for name, value in markers().items(): assert name.startswith('__plugin__.'), 'Invalid name \'%s\' is not from a plugin' % name if name in used(): group = 'current markers' else: group = 'unused markers' configs[name[plen:]] = Config(name, value, group) with open(distribution_file_path(), 'w') as f: save(configs, f)
def saveConfigurations(config): '''Saves the plugins configurations. *Attention this function is only available in an opened deploy assembly.* :param config: The configurations to save :type config: dict{str: object}. ''' if os.path.isfile(path_configuration()): os.rename(path_configuration(), '%s.%s' % (path_configuration(), 'bak')) with open(path_configuration(), 'w') as f: save(config, f) log.info('Updated the \'%s\' configuration file', path_configuration())
def persistMarkers(): ''' Persist the markers of the executed events''' plen = len('__plugin__.') configs = {} for name, value in markers().items(): assert name.startswith( '__plugin__.'), 'Invalid name \'%s\' is not from a plugin' % name if name in used(): group = 'current markers' else: group = 'unused markers' configs[name[plen:]] = Config(name, value, group) with open(distribution_file_path(), 'w') as f: save(configs, f)
def saveConfigurations(config): '''Saves the application configurations. *Attention this function is only available in an opened deploy assembly.* :param config: The configurations to save :type config: dict{str: object}. ''' if os.path.isfile(options.configuration): os.rename(options.configuration, '%s.%s' % (options.configuration, 'bak')) with open(options.configuration, 'w') as f: save(config, f) log.info('Updated the \'%s\' configuration file', options.configuration)
def dump(): assert isinstance( application.options, OptionsCore), 'Invalid application options %s' % application.options if not application.options.writeConfigurations: return if not __debug__: print( 'Cannot dump configuration file if python is run with "-O" or "-OO" option', file=sys.stderr) sys.exit(1) try: context.activate(dumpAssembly()) try: loadPlugins() configFile = configurations_file_path() if os.path.isfile(configFile): with open(configFile, 'r') as f: config = load(f) else: config = {} context.open(aop.modulesIn('__plugin__.**'), config=config, included=True) try: if os.path.isfile(configFile): os.rename(configFile, configFile + '.bak') with open(configFile, 'w') as f: save(context.configurations(force=True), f) print('Created "%s" configuration file' % configFile) finally: context.deactivate() finally: context.deactivate() except SystemExit: raise except: print('-' * 150, file=sys.stderr) print('A problem occurred while dumping configurations', file=sys.stderr) traceback.print_exc(file=sys.stderr) print('-' * 150, file=sys.stderr)
def dump(): assert isinstance(application.options, OptionsCore), 'Invalid application options %s' % application.options if not application.options.writeConfigurations: return if not __debug__: print('Cannot dump configuration file if python is run with "-O" or "-OO" option', file=sys.stderr) sys.exit(1) assembly, configFile = dumpAssembly(), application.options.configurationPath try: context.activate(assembly) try: if os.path.isfile(configFile): os.rename(configFile, configFile + '.bak') for config in assembly.configurations: try: assembly.processForName(config) except ConfigError as e: print('Failed to fetch a value for configuration \'%s\': %s' % (config, e)) # Forcing the processing of all configurations with open(configFile, 'w') as f: save(assembly.trimmedConfigurations(), f) print('Created "%s" configuration file' % configFile) finally: context.deactivate() except SystemExit: raise except: print('-' * 150, file=sys.stderr) print('A problem occurred while dumping configurations', file=sys.stderr) traceback.print_exc(file=sys.stderr) print('-' * 150, file=sys.stderr)
def config(): assert isinstance(application.options, OptionsMongrel2), 'Invalid application options %s' % application.options if not application.options.configMongrel2: return workspace = application.options.configMongrel2 folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')] folders.append(path.join('shared', 'upload')) for name in folders: folder = path.join(workspace, name) if not path.isdir(folder): makedirs(folder) configFile = application.options.configurationPath if path.isfile(configFile): with open(configFile, 'r') as f: config = load(f) else: print('The configuration file "%s" doesn\'t exist, create one by running the the application ' 'with "-dump" option, also change the application properties "server_type" configuration to "mongrel2" ' 'and also adjust the "recv_spec", "send_spec" and "server_port" accordingly' % configFile, file=sys.stderr) sys.exit(1) try: context.open(aop.modulesIn('__setup__.**'), config=config) updateConfig = False if server_type() != 'mongrel2': updateConfig = True support.persist(server_type, 'mongrel2') sendIdent = send_ident() if sendIdent is None: updateConfig = True sendIdent = str(uuid4()) support.persist(send_ident, sendIdent) replace = {} try: replace['${send_spec}'] = send_spec() replace['${send_ident}'] = sendIdent replace['${recv_spec}'] = recv_spec() replace['${recv_ident}'] = recv_ident() replace['${server_port}'] = str(server_port()) if updateConfig: if path.isfile(configFile): renames(configFile, configFile + '.bak') with open(configFile, 'w') as f: save(context.configurations(force=True), f) print('Updated the "%s" configuration file' % configFile) finally: context.deactivate() except SystemExit: raise except: print('-' * 150, file=sys.stderr) print('A problem occurred while configuring Mongrel2', file=sys.stderr) traceback.print_exc(file=sys.stderr) print('-' * 150, file=sys.stderr) else: conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf')) conf = codecs.getreader('utf8')(conf) conf = ReplaceInFile(conf, replace) with open(path.join(workspace, 'ally.conf'), 'w') as f: pipe(conf, f) with open(path.join(workspace, 'README-Mongrel2.txt'), 'wb') as f: pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f) print('Configured "%s" mongrel2 workspace' % workspace)