[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[circle] for review: chat_commands.py: minor cleanups & fixes
From: |
Peter Moulder |
Subject: |
[circle] for review: chat_commands.py: minor cleanups & fixes |
Date: |
Fri, 16 May 2003 15:23:55 +1000 |
User-agent: |
Mutt/1.5.3i |
Nothing too exciting here, just posting first from principle that it
won't hurt to delay committing for a couple of days, and give
opportunity to comment.
One thing I'm uncertain of is the right requirement for the 'name'
attribute of file reference objects for do_take. Testing shows that
it at least is often a 16-byte string (i.e. matches template 'name'),
but I'd need to analyse the source to determine whether or not anything
else is possible & can be handled.
pjm.
chat_commands.py commit msg:
Namespace fixes.
Remove redundant imports, and sort the remainder.
do_join: rename chat object parameter from `self' to `chat_obj', as
first part of merge with my local version in gtk1 branch.
Rename arg 2 of a few things from param to params, to show its list
nature. Or params_dummy for argless commands.
do_take: Stricter checking on file reference objects, which prevents
tracebacks in some cases.
Index: chat_commands.py
===================================================================
RCS file: /home/cvsroot/circle/circlelib/chat_commands.py,v
retrieving revision 1.53
diff -d -u -t -r1.53 chat_commands.py
--- chat_commands.py 14 May 2003 04:44:01 -0000 1.53
+++ chat_commands.py 16 May 2003 05:15:01 -0000
@@ -8,17 +8,20 @@
# - Ideally want to make it hard for the user to shoot self in foot.
#
-import os, re, string, time
+import os.path
+import re
+import string
+import sys
+import time
+import traceback
import types
-import utility
import chat, search, hash
-
-import settings
-import safe_pickle
-import file_server
-import error
import check
+import error
+import safe_pickle
+import settings
+import utility
def find_task(self, list, online_only=0):
@@ -63,7 +66,7 @@
if bad:
continue
- #address_name = hostname_of_ip(item[0][0])
+ #address_name = utility.hostname_of_ip(item[0][0])
self.lock.acquire()
try:
@@ -88,14 +91,14 @@
utility.mainthread_call(self.show, _('Search complete.\n'))
-def do_join(self, param):
- if not param:
- if not self.channel:
- self.show(_('Use /join <nickname> to talk to someone.\n'))
- self.set_channel([ ])
+def do_join(chat_obj, params):
+ if not params:
+ if not chat_obj.channel:
+ chat_obj.show(_('Use /join <nickname> to talk to someone.\n'))
+ chat_obj.set_channel([ ])
return
- param = param[0]
+ param = params[0]
if param[0] in '+-':
prefix = param[0]
param = param[1:]
@@ -103,7 +106,7 @@
prefix = ''
new_list = utility.split_list(param)
- old_list = self.channel[:]
+ old_list = chat_obj.channel[:]
if prefix == '+':
for item in old_list:
@@ -115,20 +118,20 @@
if item in old_list:
old_list.remove(item)
else:
- self.show(_('Not joined to %s\n')%item)
+ chat_obj.show(_('Not joined to %s\n')%item)
new_list = old_list
- self.set_channel(new_list)
- self.show(_('Joined %s\n') % string.join(self.channel,',') )
+ chat_obj.set_channel(new_list)
+ chat_obj.show(_('Joined %s\n') % string.join(chat_obj.channel,',') )
-def do_listen(self, param):
- if not param:
+def do_listen(self, params):
+ if not params:
self.show(_('Listening to %s\n') %
string.join(self.app.channels.get_listening(),',') )
return
- param = param[0]
+ param = params[0]
if param[0] in '+-':
prefix = param[0]
param = param[1:]
@@ -228,13 +231,9 @@
ref = self.exec_vars[what]
source = self.exec_vars[what+'_source']
- #if type(ref) != type({}) or \
- # ref.get('type',None) != 'file' or \
- # type(ref.get('filename',None)) != type('') or \
- # type(ref.get('name',None)) != type(''):
- if not check.matches(ref,
- {'type':'string','filename':'text','name':'text'}) or \
- ref['type'] != 'file':
+ if not (check.matches(ref,
+ {'type':'string', 'filename':'text', 'name':'name',
'length':'integer'})
+ and ref['type'] == 'file'):
self.show(_('Not a reference to a file.\n'))
return
@@ -246,7 +245,7 @@
finally:
self.lock.release()
-def do_recall(self, param):
+def do_recall(self, params_dummy):
def recall_task(self,recall_list,field):
if recall_list == [ ]:
utility.mainthread_call(field.show, _('No message to recall.\n'),
['grey'])
@@ -343,9 +342,12 @@
if item.watch:
utility.Task(look_task, self, item.nickname,
self.get_field()).start()
-def do_who(self, param):
- self.do_who()
-
+def do_who(chat_obj, params_dummy):
+ # todo: Accept an argument, which does something like
+ # search.search_for_people_on_channel(params[0], chat_obj.node,
chat_obj.app)
+ # except that it sends to the chat widget like /find -o.
+ chat_obj.do_who()
+
def do_help(self, param):
if param:
# Discard all but first word.
@@ -362,7 +364,7 @@
try:
utility.browse_file("chat_commands.html", section)
except error.Error, err:
- error.show(self.app.window)
+ err.show(self.app.window)
else:
utility.stdin_echo(1)
try:
@@ -371,14 +373,14 @@
self.show(err.message+'\n')
utility.stdin_echo(0)
-def do_post(self, param):
+def do_post(self, params_dummy):
if not self.use_gtk:
self.show(_("This feature does not currently work with the text
interface, sorry.\n"))
return
self.app.gossip.prompt_for_wodge()
-def do_gossip(self, param):
+def do_gossip(self, params_dummy):
if not self.use_gtk:
self.show(_("This feature does not currently work with the text
interface, sorry.\n"))
return
@@ -387,22 +389,22 @@
def do_stats(self, param):
node = self.app.node
- node.acquire_read_lock('stat')
+ node.acquire_lock('stat')
try:
tot = node.network_usage
prof = node.network_profile
npeers = len(node.peers)
finally:
- node.release_read_lock('stat')
+ node.release_lock('stat')
str = (_('Network usage so far: %s\nNumber of known peers: %d\n')
- % (human_size(tot), npeers))
+ % (utility.human_size(tot), npeers))
if param and param[0] in ('-p', '--profile'):
str += _('Profile:\n')
prof_items = map(lambda item: (item[1][1], item[1][0], item[0]),
prof.items())
prof_items.sort()
for nbytes,count,key in prof_items:
- str += (' ' + key + ': \t' + human_size(nbytes)
+ str += (' ' + key + ': \t' + utility.human_size(nbytes)
+ _(' in %d items\n') % count)
self.show(str)
@@ -499,7 +501,7 @@
finally:
chat_obj.lock.release()
-def do_read(self, param):
+def do_read(self, params_dummy):
self.show(_('Displaying unread messages.\n'))
self.lock.acquire()
try:
@@ -584,7 +586,7 @@
message = ''
self.app.shutdown(message, 1)
-def do_clear(chat_obj, ignored__param):
+def do_clear(chat_obj, params_dummy):
if chat_obj.use_gtk:
chat_obj.clear()
@@ -619,4 +621,4 @@
self.register("clear", 0,0, do_clear)
-# vim: set expandtab :
+# vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
- [circle] for review: chat_commands.py: minor cleanups & fixes,
Peter Moulder <=