new config file management
This commit is contained in:
parent
2592032962
commit
48258e96d5
59
core/core.py
59
core/core.py
|
@ -17,7 +17,7 @@
|
||||||
## GNU General Public License for more details.
|
## GNU General Public License for more details.
|
||||||
##
|
##
|
||||||
|
|
||||||
import sys
|
import sys, os
|
||||||
|
|
||||||
sys.path.append("..")
|
sys.path.append("..")
|
||||||
import time
|
import time
|
||||||
|
@ -37,16 +37,44 @@ class GajimCore:
|
||||||
"""Core"""
|
"""Core"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
|
self.init_cfg_file()
|
||||||
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
|
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
|
||||||
self.hub = common.hub.GajimHub()
|
self.hub = common.hub.GajimHub()
|
||||||
self.parse()
|
self.parse()
|
||||||
# END __init__
|
# END __init__
|
||||||
|
|
||||||
|
def init_cfg_file(self):
|
||||||
|
fname = os.path.expanduser(CONFPATH)
|
||||||
|
reps = string.split(fname, '/')
|
||||||
|
del reps[0]
|
||||||
|
path = ''
|
||||||
|
while len(reps) > 1:
|
||||||
|
path = path + '/' + reps[0]
|
||||||
|
del reps[0]
|
||||||
|
try:
|
||||||
|
os.stat(os.path.expanduser(path))
|
||||||
|
except OSError:
|
||||||
|
try:
|
||||||
|
os.mkdir(os.path.expanduser(path))
|
||||||
|
except:
|
||||||
|
print "Can't create %s" % path
|
||||||
|
sys.exit
|
||||||
|
try:
|
||||||
|
os.stat(fname)
|
||||||
|
except:
|
||||||
|
print "creating %s" % fname
|
||||||
|
fic = open(fname, "w")
|
||||||
|
fic.write("[Profile]\naccounts = \n\n[Core]\ndelauth = 1\nalwaysauth = 0\nmodules = logger gtkgui\ndelroster = 1\n")
|
||||||
|
fic.close()
|
||||||
|
# END init_cfg_file
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
self.cfgParser.parseCfgFile()
|
self.cfgParser.parseCfgFile()
|
||||||
self.accounts = {}
|
self.accounts = {}
|
||||||
accts = self.cfgParser.tab['Profile']['accounts']
|
accts = string.split(self.cfgParser.tab['Profile']['accounts'], ' ')
|
||||||
for a in string.split(accts, ' '):
|
if accts == ['']:
|
||||||
|
accts = []
|
||||||
|
for a in accts:
|
||||||
self.accounts[a] = self.cfgParser.tab[a]
|
self.accounts[a] = self.cfgParser.tab[a]
|
||||||
|
|
||||||
def vCardCB(self, con, vc):
|
def vCardCB(self, con, vc):
|
||||||
|
@ -95,7 +123,10 @@ class GajimCore:
|
||||||
self.hub.sendPlugin('NOTIFY', (who, 'offline', 'offline', \
|
self.hub.sendPlugin('NOTIFY', (who, 'offline', 'offline', \
|
||||||
prs.getFrom().getResource()))
|
prs.getFrom().getResource()))
|
||||||
else:
|
else:
|
||||||
self.hub.sendPlugin('SUBSCRIBE', who)
|
txt = prs.getStatus()
|
||||||
|
if not txt:
|
||||||
|
txt = "I would like to add you to my roster."
|
||||||
|
self.hub.sendPlugin('SUBSCRIBE', (who, 'txt'))
|
||||||
elif type == 'subscribed':
|
elif type == 'subscribed':
|
||||||
jid = prs.getFrom()
|
jid = prs.getFrom()
|
||||||
self.hub.sendPlugin('SUBSCRIBED', {'jid':jid.getBasic(), \
|
self.hub.sendPlugin('SUBSCRIBED', {'jid':jid.getBasic(), \
|
||||||
|
@ -193,19 +224,26 @@ class GajimCore:
|
||||||
self.con.disconnect()
|
self.con.disconnect()
|
||||||
self.hub.sendPlugin('QUIT', ())
|
self.hub.sendPlugin('QUIT', ())
|
||||||
return
|
return
|
||||||
#('ASK_CONFIG', (who_ask, section))
|
#('ASK_CONFIG', (who_ask, section, default_config))
|
||||||
elif ev[0] == 'ASK_CONFIG':
|
elif ev[0] == 'ASK_CONFIG':
|
||||||
if ev[1][1] == 'accounts':
|
if ev[1][1] == 'accounts':
|
||||||
self.hub.sendPlugin('CONFIG', (ev[1][0], self.accounts))
|
self.hub.sendPlugin('CONFIG', (ev[1][0], self.accounts))
|
||||||
else:
|
else:
|
||||||
self.hub.sendPlugin('CONFIG', (ev[1][0], \
|
if self.cfgParser.tab.has_key(ev[1][1]):
|
||||||
self.cfgParser.__getattr__(ev[1][1])))
|
self.hub.sendPlugin('CONFIG', (ev[1][0], \
|
||||||
|
self.cfgParser.__getattr__(ev[1][1])))
|
||||||
|
else:
|
||||||
|
self.cfgParser.tab[ev[1][1]] = ev[1][2]
|
||||||
|
self.cfgParser.writeCfgFile()
|
||||||
|
self.hub.sendPlugin('CONFIG', (ev[1][0], ev[1][2]))
|
||||||
#('CONFIG', (section, config))
|
#('CONFIG', (section, config))
|
||||||
elif ev[0] == 'CONFIG':
|
elif ev[0] == 'CONFIG':
|
||||||
if ev[1][0] == 'accounts':
|
if ev[1][0] == 'accounts':
|
||||||
#Remove all old accounts
|
#Remove all old accounts
|
||||||
accts = string.split(self.cfgParser.tab\
|
accts = string.split(self.cfgParser.tab\
|
||||||
['Profile']['accounts'], ' ')
|
['Profile']['accounts'], ' ')
|
||||||
|
if accts == ['']:
|
||||||
|
accts = []
|
||||||
for a in accts:
|
for a in accts:
|
||||||
del self.cfgParser.tab[a]
|
del self.cfgParser.tab[a]
|
||||||
#Write all new accounts
|
#Write all new accounts
|
||||||
|
@ -241,7 +279,12 @@ class GajimCore:
|
||||||
#('SUB', (jid, txt))
|
#('SUB', (jid, txt))
|
||||||
elif ev[0] == 'SUB':
|
elif ev[0] == 'SUB':
|
||||||
log.debug('subscription request for %s' % ev[1][0])
|
log.debug('subscription request for %s' % ev[1][0])
|
||||||
self.con.send(common.jabber.Presence(ev[1][0], 'subscribe'))
|
pres = common.jabber.Presence(ev[1][0], 'subscribe')
|
||||||
|
if ev[1][1]:
|
||||||
|
pres.setStatus(ev[1][1])
|
||||||
|
else:
|
||||||
|
pres.setStatus("I would like to add you to my roster.")
|
||||||
|
self.con.send(pres)
|
||||||
#('REQ', jid)
|
#('REQ', jid)
|
||||||
elif ev[0] == 'AUTH':
|
elif ev[0] == 'AUTH':
|
||||||
self.con.send(common.jabber.Presence(ev[1], 'subscribed'))
|
self.con.send(common.jabber.Presence(ev[1], 'subscribed'))
|
||||||
|
|
|
@ -2673,7 +2673,7 @@ on the server.</property>
|
||||||
<property name="ypad">0</property>
|
<property name="ypad">0</property>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="padding">0</property>
|
<property name="padding">5</property>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
</packing>
|
</packing>
|
||||||
|
|
|
@ -588,7 +588,7 @@ class accountPreference_Window:
|
||||||
del self.accs.r.plugin.accounts[self.acc]
|
del self.accs.r.plugin.accounts[self.acc]
|
||||||
#if it's a new account
|
#if it's a new account
|
||||||
else:
|
else:
|
||||||
if name in self.accs.r.accounts:
|
if name in self.accs.r.plugin.accounts:
|
||||||
warning_Window('An account already has this name')
|
warning_Window('An account already has this name')
|
||||||
return 0
|
return 0
|
||||||
#if we neeed to register a new account
|
#if we neeed to register a new account
|
||||||
|
@ -664,7 +664,7 @@ class accounts_Window:
|
||||||
(mod, iter) = sel.get_selected()
|
(mod, iter) = sel.get_selected()
|
||||||
model = self.treeview.get_model()
|
model = self.treeview.get_model()
|
||||||
account = model.get_value(iter, 0)
|
account = model.get_value(iter, 0)
|
||||||
del self.r.plugin.accountsi[account]
|
del self.r.plugin.accounts[account]
|
||||||
self.r.queueOUT.put(('CONFIG', ('accounts', self.r.plugin.accounts)))
|
self.r.queueOUT.put(('CONFIG', ('accounts', self.r.plugin.accounts)))
|
||||||
self.init_accounts()
|
self.init_accounts()
|
||||||
|
|
||||||
|
@ -755,12 +755,14 @@ class authorize_Window:
|
||||||
self.r.queueOUT.put(('DENY', self.jid))
|
self.r.queueOUT.put(('DENY', self.jid))
|
||||||
self.delete_event(self)
|
self.delete_event(self)
|
||||||
|
|
||||||
def __init__(self, roster, jid):
|
def __init__(self, roster, jid, txt):
|
||||||
xml = gtk.glade.XML(GTKGUI_GLADE, 'Sub_req')
|
xml = gtk.glade.XML(GTKGUI_GLADE, 'Sub_req')
|
||||||
self.window = xml.get_widget('Sub_req')
|
self.window = xml.get_widget('Sub_req')
|
||||||
self.r = roster
|
self.r = roster
|
||||||
self.jid = jid
|
self.jid = jid
|
||||||
xml.get_widget('label').set_text('Subscription request from ' + self.jid)
|
xml.get_widget('label').set_text('Subscription request from ' + self.jid)
|
||||||
|
#TOTOTO
|
||||||
|
xml.get_widget("textview_sub").get_buffer().set_text(txt)
|
||||||
xml.signal_connect('on_button_auth_clicked', self.auth)
|
xml.signal_connect('on_button_auth_clicked', self.auth)
|
||||||
xml.signal_connect('on_button_deny_clicked', self.deny)
|
xml.signal_connect('on_button_deny_clicked', self.deny)
|
||||||
xml.signal_connect('on_button_close_clicked', self.delete_event)
|
xml.signal_connect('on_button_close_clicked', self.delete_event)
|
||||||
|
@ -1199,8 +1201,11 @@ class roster_Window:
|
||||||
txt = w.run()
|
txt = w.run()
|
||||||
else:
|
else:
|
||||||
txt = widget.name
|
txt = widget.name
|
||||||
self.queueOUT.put(('STATUS',(widget.name, txt, \
|
if len(self.plugin.accounts) > 0:
|
||||||
self.plugin.accounts.keys()[0])))
|
self.queueOUT.put(('STATUS',(widget.name, txt, \
|
||||||
|
self.plugin.accounts.keys()[0])))
|
||||||
|
else:
|
||||||
|
warning_Window("You must setup an account before connecting to jabber network.")
|
||||||
|
|
||||||
def on_prefs(self, widget):
|
def on_prefs(self, widget):
|
||||||
"""When preferences is selected :
|
"""When preferences is selected :
|
||||||
|
@ -1518,7 +1523,7 @@ class plugin:
|
||||||
self.r.tab_messages[jid].print_conversation(ev[1][1])
|
self.r.tab_messages[jid].print_conversation(ev[1][1])
|
||||||
|
|
||||||
elif ev[0] == 'SUBSCRIBE':
|
elif ev[0] == 'SUBSCRIBE':
|
||||||
authorize_Window(self.r, ev[1])
|
authorize_Window(self.r, ev[1][0], ev[1][1])
|
||||||
elif ev[0] == 'SUBSCRIBED':
|
elif ev[0] == 'SUBSCRIBED':
|
||||||
jid = ev[1]['jid']
|
jid = ev[1]['jid']
|
||||||
if self.r.l_contact.has_key(jid):
|
if self.r.l_contact.has_key(jid):
|
||||||
|
@ -1586,7 +1591,16 @@ class plugin:
|
||||||
gtk.threads_init()
|
gtk.threads_init()
|
||||||
gtk.threads_enter()
|
gtk.threads_enter()
|
||||||
self.queueIN = quIN
|
self.queueIN = quIN
|
||||||
quOUT.put(('ASK_CONFIG', ('GtkGui', 'GtkGui')))
|
quOUT.put(('ASK_CONFIG', ('GtkGui', 'GtkGui', {'autopopup':1,\
|
||||||
|
'showoffline':0,\
|
||||||
|
'autoaway':0,\
|
||||||
|
'autoawaytime':10,\
|
||||||
|
'autoxa':0,\
|
||||||
|
'autoxatime':20,\
|
||||||
|
'iconstyle':'sun',\
|
||||||
|
'inmsgcolor':'#ff000',\
|
||||||
|
'outmsgcolor': '#0000ff',\
|
||||||
|
'statusmsgcolor':'#1eaa1e'})))
|
||||||
self.config = self.wait('CONFIG')
|
self.config = self.wait('CONFIG')
|
||||||
quOUT.put(('ASK_CONFIG', ('GtkGui', 'accounts')))
|
quOUT.put(('ASK_CONFIG', ('GtkGui', 'accounts')))
|
||||||
self.accounts = self.wait('CONFIG')
|
self.accounts = self.wait('CONFIG')
|
||||||
|
|
|
@ -83,7 +83,8 @@ class plugin:
|
||||||
def __init__(self, quIN, quOUT):
|
def __init__(self, quIN, quOUT):
|
||||||
self.queueIN = quIN
|
self.queueIN = quIN
|
||||||
self.queueOUT = quOUT
|
self.queueOUT = quOUT
|
||||||
quOUT.put(('ASK_CONFIG', ('Logger', 'Logger')))
|
quOUT.put(('ASK_CONFIG', ('Logger', 'Logger', {\
|
||||||
|
'lognotsep':1, 'lognotusr':1})))
|
||||||
self.config = self.wait('CONFIG')
|
self.config = self.wait('CONFIG')
|
||||||
#create ~/.gajim/logs/ if it doesn't exist
|
#create ~/.gajim/logs/ if it doesn't exist
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue