# # Logformatter, version 0.2 for weechat version 0.3.0 or 0.3.1 # (this script is *NOT NEEDED* for WeeChat 0.3.2 where feature is in logger plugin) # # Allows formatting of log filenames with date # # Update: # 0.1 # 0.2 - Added functionality for changing config auto detection. # # Copyright (C) 2009 David Rubin # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # 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, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # try: import weechat import_ok = True except: print "This script must be run under WeeChat." print "Get WeeChat now at: http://www.weechat.org/" import_ok = False import time from UserDict import UserDict SCRIPT_NAME = "logformatter" SCRIPT_AUTHOR = "David Rubin " SCRIPT_VERSION = "0.2" SCRIPT_LICENSE = "GPL" SCRIPT_DESC = "Provides functionality to have date/time in logfiles." CONFIG_FILE_NAME= "logformatter" class Settings(UserDict): def __init__(self): UserDict.__init__(self) self.data = {} self.config_file = weechat.config_new(CONFIG_FILE_NAME, "lf_config_reload_cb", "") section_default = weechat.config_new_section( self.config_file, "default", 0, 0, "", "", "", "", "", "", "", "", "", "") if not self.config_file: return self.data['file.mask']=weechat.config_new_option( self.config_file, section_default, "file.mask", "string", """The log format""", "", 0, 0, "$plugin.$name.weechatlog", "$plugin.$name.weechatlog", 0, "", "", "", "", "", "") self.data['file.path']=weechat.config_new_option( self.config_file, section_default, "file.path", "string", """The log format""", "", 0, 0, "%%h/logs/", "%%h/logs/", 0, "", "", "", "", "", "") self.data['update_interval']=weechat.config_new_option( self.config_file, section_default, "update_interval", "string", """How often to update it""", "", 0, 0, "1", "1", 0, "", "", "", "", "", "") weechat.config_read(self.config_file) def __getitem__(self, key): return weechat.config_string(self.data[key]) def lf_config_reload_cb(data, config_file): """ Reload configuration file. """ temp = weechat.config_read(config_file) lf_update() return temp def lf_config(): lf_update() def lf_unload_script(): """ Function called when script is unloaded. """ global settings weechat.config_write(settings.config_file) return weechat.WEECHAT_RC_OK def lf_call_back(data, remaining): lf_update() return weechat.WEECHAT_RC_OK def lf_update(): global settings path = weechat.config_get ("logger.file.path") mask = weechat.config_get ("logger.file.mask") temp_path=time.strftime(settings['file.path']) temp_mask=time.strftime(settings['file.mask']) weechat.config_option_set (path, temp_path, 1) weechat.config_option_set (mask,temp_mask, 1) #Main stuff if ( import_ok and weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,SCRIPT_DESC, "lf_unload_script", "") ): settings = Settings() weechat.hook_config("%s.*" % CONFIG_FILE_NAME, "lf_config", ""); weechat.hook_timer (int(settings['update_interval']) * 1000, 0, 0, "lf_call_back", "") else: print "failed to load weechat"