Skip to content

Instantly share code, notes, and snippets.

@dchaplinsky
Created May 16, 2013 13:49
Show Gist options
  • Select an option

  • Save dchaplinsky/5591861 to your computer and use it in GitHub Desktop.

Select an option

Save dchaplinsky/5591861 to your computer and use it in GitHub Desktop.
diff --git a/circus/arbiter.py b/circus/arbiter.py
index 006fed3..303b1ab 100644
--- a/circus/arbiter.py
+++ b/circus/arbiter.py
@@ -146,8 +146,8 @@ class Arbiter(object):
self.check_delay)
@classmethod
- def load_from_config(cls, config_file):
- cfg = get_config(config_file)
+ def load_from_config(cls, config_file, format="circus"):
+ cfg = get_config(config_file, format)
watchers = []
for watcher in cfg.get('watchers', []):
diff --git a/circus/circusd.py b/circus/circusd.py
index a525beb..393a371 100644
--- a/circus/circusd.py
+++ b/circus/circusd.py
@@ -53,6 +53,8 @@ def daemonize():
def main():
parser = argparse.ArgumentParser(description='Run some watchers.')
parser.add_argument('config', help='configuration file', nargs='?')
+ parser.add_argument('--format', dest='format', default='circus',
+ help="format for configuration file: circus or supervisord")
# XXX we should be able to add all these options in the config file as well
parser.add_argument('--log-level', dest='loglevel', default='info',
@@ -68,6 +70,7 @@ def main():
help="Start circusd in the background")
parser.add_argument('--pidfile', dest='pidfile')
parser.add_argument('--version', action='store_true', default=False,
+
help='Displays Circus version and exits.')
args = parser.parse_args()
@@ -97,7 +100,7 @@ def main():
configure_logger(logger, args.loglevel, args.logoutput)
# load the arbiter from config
- arbiter = Arbiter.load_from_config(args.config)
+ arbiter = Arbiter.load_from_config(args.config, args.format)
try:
arbiter.start()
except KeyboardInterrupt:
diff --git a/circus/config.py b/circus/config.py
index 422bca2..41a2fd2 100644
--- a/circus/config.py
+++ b/circus/config.py
@@ -65,7 +65,7 @@ class DefaultConfigParser(StrictConfigParser):
raise NotImplementedError()
-def read_config(config_path):
+def read_config(config_path, include_section="circus", include_field="include"):
cfg = DefaultConfigParser()
with open(config_path) as f:
cfg.readfp(f)
@@ -92,10 +92,10 @@ def read_config(config_path):
elif os.path.isfile(filename):
includes.append(filename)
- for include_file in cfg.dget('circus', 'include', '').split():
+ for include_file in cfg.dget(include_section, include_field, '').split():
include_filename(include_file)
- for include_dir in cfg.dget('circus', 'include_dir', '').split():
+ for include_dir in cfg.dget(include_section, 'include_dir', '').split():
include_filename(os.path.join(include_dir, '*.ini'))
logger.debug('reading config files: %s' % includes)
@@ -104,15 +104,30 @@ def read_config(config_path):
return cfg, cfg_files_read
-
-def get_config(config_file):
+def get_config(config_file, format="circus"):
if not os.path.exists(config_file):
sys.stderr.write("the configuration file %r does not exist\n" %
config_file)
sys.stderr.write("Exiting...\n")
sys.exit(1)
- cfg, cfg_files_read = read_config(config_file)
+ if format == "circus":
+ cfg, cfg_files_read = read_config(config_file)
+ return _get_circus_config(cfg, cfg_files_read)
+ elif format == "supervisord":
+ cfg, cfg_files_read = read_config(config_file, include_section="include",
+ include_field="files")
+ return _get_supervisord_config(cfg, cfg_files_read)
+ else:
+ sys.stderr.write("Unknown config file format: %s\n" %
+ format)
+ sys.stderr.write("Exiting...\n")
+ sys.exit(1)
+
+
+ return None, None
+
+def _get_circus_config(cfg, cfg_files_read):
dget = cfg.dget
config = {}
@@ -247,3 +262,14 @@ def get_config(config_file):
config['plugins'] = plugins
config['sockets'] = sockets
return config
+
+
+def _get_supervisord_config(cfg, cfg_files_read):
+ dget = cfg.dget
+ config = {}
+
+ sys.stderr.write("Not implemented yet\n")
+ sys.stderr.write("Exiting...\n")
+ sys.exit(1)
+
+ pass
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment