Commits

Nik Cubrilovic committed 509d5d6

editconfig

Comments (0)

Files changed (3)

cexbot/__init__.py

 import sys
 import os
 
-VERSION = (0, 0, 9, 'dev', 1)
+VERSION = (0, 0, 9, 'dev', 4)
 
 __clsname__ = 'cexbot'
 __author__ = 'Nik Cubrilovic <nikcub@gmail.com>'

cexbot/command_utils.py

   logging.basicConfig(level=log_level, format="%(asctime)s %(levelname)s: %(message)s")
 
   if args.task == 'genconfig':
-    return config.write_blank()
+    return cexbot.config.write_blank()
+
+  if args.task == 'editconfig':
+    return cexbot.config.edit_config()
 
   if args.task == 'update':
     return check_update()
 import os
 import logging
 import ConfigParser
+import subprocess
 
 CNF_NAME = 'cex.cnf'
+CNF_SEARCHPATHS = ['.', '~', '/etc']
 CONFIG_DEFAULTS = {
 	'auth': {
 		'username': '',
 		parser.write(config_file)
 	logging.info("Blank config file written to %s" % config_file)
 
+def get_cwd():
+  if not '__file__' in globals():
+    cwd = os.path.abspath(os.getcwd())
+  else:
+    cwd = os.path.dirname(os.path.abspath(__file__))
+  return os.path.realpath(cwd)
+
+def get_config_file():
+	cwd = get_cwd()
+	for p in CNF_SEARCHPATHS:
+		tp = os.path.join('.')
+
+def edit_config():
+	config_file = CNF_NAME
+	editor = os.environ.get('EDITOR','vim')
+	subprocess.call([editor, config_file])
+	return True
+
 def get_config():
 	parser = cnf_object()
 	parser.read([CNF_NAME, os.path.expanduser('~/.' + CNF_NAME), os.path.realpath('/etc/' + CNF_NAME)])
 	except BadConfig, e:
 		logging.error(str(e))
 
-	return parser
+	return parser