Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--irc_config.cfg6
-rw-r--r--ircactivity.py45
2 files changed, 45 insertions, 6 deletions
diff --git a/irc_config.cfg b/irc_config.cfg
index d8ee977..f28cc1e 100644
--- a/irc_config.cfg
+++ b/irc_config.cfg
@@ -1,5 +1,7 @@
[Config]
# Uncomment the following line to set a default nick
# Nick: NameyName
-Server: irc.freenode.net
-Channels: #sugar, #sugar-es
+# Uncomment the following line to set a default server
+# Server: irc.freenode.net
+# Uncomment the following line to set a default channel
+# Channels: #sugar, #sugar-es \ No newline at end of file
diff --git a/ircactivity.py b/ircactivity.py
index b69d71e..e61014c 100644
--- a/ircactivity.py
+++ b/ircactivity.py
@@ -114,31 +114,68 @@ class IRCActivity(activity.Activity):
if os.path.exists(ETC_CONFIG_PATH):
self.read_defaults_from_config(ETC_CONFIG_PATH)
elif os.path.exists(DEFAULT_CONFIG_PATH):
- self.read_defaults_from_config(DEFAULT_CONFIG_PATH)
+ data = self.read_defaults_from_config(DEFAULT_CONFIG_PATH)
+ if not data["server"]:
+ self.client.join_server('us.freenode.net')
+ if not data["channels"]:
+ self.channels_config()
else:
self.client.join_server('us.freenode.net')
- self.client.add_channel('#sugar')
- self.client.add_channel_other('#sugar-es')
+ self.channels_config()
+
+ def channels_config(self):
+ locale = os.environ["LANG"]
+ channel = "#sugar"
+
+ if locale:
+ locale = locale.split("_")[0]
+ if locale != "en":
+ channel = "#sugar-%s" % locale
+ else:
+ pass
+
+ self.client.add_channel(channel)
def read_defaults_from_config(self, config_file):
logging.debug('Reading configuration from file %s' % config_file)
fp = open(config_file)
config = ConfigParser.ConfigParser()
- config.readfp(fp)
+
+ try:
+ config.readfp(fp)
+ except Exception, error:
+ logging.debug('Reading configuration, error: %s' % error)
+ return {"server": None, "channels": None}
+
fp.close()
+ DATA = {}
+
if config.has_section('Config'):
if config.has_option('Config', 'Nick'):
nick = config.get('Config', 'Nick').strip()
self.client.run_command('NICK %s' % (nick))
+
if config.has_option('Config', 'Server'):
server = config.get('Config', 'Server').strip()
self.client.join_server(server)
+ DATA["server"] = server
+ else:
+ DATA["server"] = None
+
if config.has_option('Config', 'Channels'):
channels = config.get('Config', 'Channels').split(',')
+ DATA["channels"] = channels
for channel in channels:
self.client.add_channel(channel.strip())
self.client.add_channel_other(channel.strip())
+ else:
+ DATA["channels"] = None
+ else:
+ DATA["server"] = None
+ DATA["channels"] = None
+
+ return DATA
def read_file(self, file_path):
if self.metadata['mime_type'] != 'text/plain':