[hackers] [wmii] Minor pygmi efficiency fixed. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Thu, 21 May 2009 19:57:06 +0000 (UTC)

changeset: 2461:b9b5a6c675a8
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Thu May 21 15:57:04 2009 -0400
files: alternative_wmiircs/python/pygmi/fs.py alternative_wmiircs/python/pyxp/asyncclient.py alternative_wmiircs/python/pyxp/client.py cmd/wmii/bar.c cmd/wmii/fns.h cmd/wmii/fs.c
description:
Minor pygmi efficiency fixed.

diff -r b63a6adce614 -r b9b5a6c675a8 alternative_wmiircs/python/pygmi/fs.py
--- a/alternative_wmiircs/python/pygmi/fs.py Thu May 21 14:38:38 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/fs.py Thu May 21 15:57:04 2009 -0400
@@ -337,28 +337,41 @@
         self.name = name
         self.base_path = self.sides[side]
         self.path = '%s/%s' % (self.base_path, self.name)
- self.create(colors, label)
+ self.file = None
+ if colors or label:
+ self.create(colors, label)
 
     def create(self, colors=None, label=None):
- with client.create(self.path, OWRITE) as f:
- f.write(self.getval(colors, label))
+ if not self.file:
+ self.file = client.create(self.path, ORDWR)
+ if colors:
+ self.file.awrite(self.getval(colors, label), offset=0)
+ elif label:
+ self.file.awrite(label, offset=24)
     def remove(self):
- client.aremove(self.path)
+ if self.file:
+ self.file.aremove()
+ self.file = None
 
     def getval(self, colors=None, label=None):
- if colors is None:
- colors = self.colors
         if label is None:
             label = self.label
+ if colors is None and re.match(
+ r'#[0-9a-f]{6} #[0-9a-f]{6} #[0-9a-f]{6}', label, re.I):
+ colors = self.colors
+ if not colors:
+ return str(label)
         return ' '.join([Color(c).hex for c in colors] + [str(label)])
 
     colors = property(
- lambda self: tuple(map(Color, client.read(self.path).split(' ')[:3])),
- lambda self, val: client.awrite(self.path, self.getval(colors=val)))
+ lambda self: self.file and
+ tuple(map(Color, self.file.read(offset=0).split(' ')[:3]))
+ or (),
+ lambda self, val: self.create(colors=val))
 
     label = property(
- lambda self: client.read(self.path).split(' ', 3)[3],
- lambda self, val: client.write(self.path, self.getval(label=val)))
+ lambda self: self.file and self.file.read(offset=0).split(' ', 3)[3] or '',
+ lambda self, val: self.create(label=val))
 
     @classmethod
     def all(cls, side):
@@ -516,7 +529,7 @@
             self.add(t.id)
         for b in wmii.lbuttons:
             if b.name not in self.tags:
- b.aremove()
+ b.remove()
         self.focus(Tag('sel').id)
 
         self.mru = [self.sel.id]
diff -r b63a6adce614 -r b9b5a6c675a8 alternative_wmiircs/python/pyxp/asyncclient.py
--- a/alternative_wmiircs/python/pyxp/asyncclient.py Thu May 21 14:38:38 2009 -0400
+++ b/alternative_wmiircs/python/pyxp/asyncclient.py Thu May 21 15:57:04 2009 -0400
@@ -41,7 +41,7 @@
                        next)
         next()
 
- def _open(self, path, mode, open):
+ def _open(self, path, mode, open, origpath=None):
         resp = None
 
         with self.walk(path) as nfid:
@@ -50,18 +50,18 @@
 
         def cleanup():
             self.aclunk(fid)
- file = File(self, '/'.join(path), resp, fid, mode, cleanup)
+ file = File(self, origpath or '/'.join(path), resp, fid, mode, cleanup)
         self.files[fid] = file
 
         return file
 
- def _aopen(self, path, mode, open, callback):
+ def _aopen(self, path, mode, open, callback, origpath=None):
         resp = None
         def next(fid, exc, tb):
             def next(resp, exc, tb):
                 def cleanup():
                     self.clunk(fid)
- file = File(self, '/'.join(path), resp, fid, mode, cleanup)
+ file = File(self, origpath or '/'.join(path), resp, fid, mode, cleanup)
                 self.files[fid] = file
                 self.respond(callback, file)
             self.dorpc(open(fid), next, callback)
@@ -83,7 +83,8 @@
             def callback(resp, exc, tb):
                 if resp:
                     resp.close()
- return self._aopen(path, mode, open, async)
+ return self._aopen(path, mode, open, async,
+ origpath='/'.join(path + [name]))
 
     def aremove(self, path, callback=True):
         path = self.splitpath(path)
@@ -177,7 +178,7 @@
                 callback(None)
         self.aread(next)
 
- def awrite(self, data, callback, offset=None):
+ def awrite(self, data, callback=True, offset=None):
         ctxt = dict(offset=self.offset, off=0)
         if offset is not None:
             ctxt['offset'] = offset
diff -r b63a6adce614 -r b9b5a6c675a8 alternative_wmiircs/python/pyxp/client.py
--- a/alternative_wmiircs/python/pyxp/client.py Thu May 21 14:38:38 2009 -0400
+++ b/alternative_wmiircs/python/pyxp/client.py Thu May 21 15:57:04 2009 -0400
@@ -164,7 +164,7 @@
                     self.clunk(fid)
         return Res
 
- def _open(self, path, mode, open):
+ def _open(self, path, mode, open, origpath=None):
         resp = None
 
         with self.walk(path) as nfid:
@@ -173,7 +173,7 @@
 
         def cleanup():
             self.aclunk(fid)
- file = File(self, '/'.join(path), resp, fid, mode, cleanup)
+ file = File(self, origpath or '/'.join(path), resp, fid, mode, cleanup)
         self.files[fid] = file
 
         return file
@@ -191,7 +191,7 @@
 
         def open(fid):
             return fcall.Tcreate(fid=fid, mode=mode, name=name, perm=perm)
- return self._open(path, mode, open)
+ return self._open(path, mode, open, origpath='/'.join(path + [name]))
 
     def remove(self, path):
         path = self.splitpath(path)
@@ -245,6 +245,9 @@
         self.closed = False
 
         self.offset = 0
+ def __del__(self):
+ if not self.closed:
+ self.cleanup()
 
     def dorpc(self, fcall, async=None, error=None):
         if hasattr(fcall, 'fid'):
@@ -277,9 +280,7 @@
                     break
             if offset is None:
                 self.offset = offs
- res = ''.join(res)
- if len(res) > 0:
- return res
+ return ''.join(res)
     def readlines(self):
         last = None
         while True:
diff -r b63a6adce614 -r b9b5a6c675a8 cmd/wmii/bar.c
--- a/cmd/wmii/bar.c Thu May 21 14:38:38 2009 -0400
+++ b/cmd/wmii/bar.c Thu May 21 15:57:04 2009 -0400
@@ -184,6 +184,30 @@
         copyimage(s->barwin, r, disp.ibuf, ZP);
 }
 
+void
+bar_load(Bar *b) {
+ IxpMsg m;
+ char *p, *q;
+
+ p = b->buf;
+ m = ixp_message(p, strlen(p), 0);
+ msg_parsecolors(&m, &b->col);
+
+ q = (char*)m.end-1;
+ while(q >= (char*)m.pos && *q == '\n')
+ *q-- = '\0';
+
+ q = b->text;
+ utflcpy(q, (char*)m.pos, sizeof b->text);
+
+ p[0] = '\0';
+ strlcat(p, b->col.colstr, sizeof b->buf);
+ strlcat(p, " ", sizeof b->buf);
+ strlcat(p, b->text, sizeof b->buf);
+
+ bar_draw(b->screen);
+}
+
 Bar*
 bar_find(Bar *bp, const char *name) {
         Bar *b;
diff -r b63a6adce614 -r b9b5a6c675a8 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Thu May 21 14:38:38 2009 -0400
+++ b/cmd/wmii/fns.h Thu May 21 15:57:04 2009 -0400
@@ -61,6 +61,7 @@
 void bar_draw(WMScreen*);
 Bar* bar_find(Bar*, const char*);
 void bar_init(WMScreen*);
+void bar_load(Bar*);
 void bar_resize(WMScreen*);
 void bar_sety(WMScreen*, int);
 void bar_setbounds(WMScreen*, int, int);
diff -r b63a6adce614 -r b9b5a6c675a8 cmd/wmii/fs.c
--- a/cmd/wmii/fs.c Thu May 21 14:38:38 2009 -0400
+++ b/cmd/wmii/fs.c Thu May 21 15:57:04 2009 -0400
@@ -545,6 +545,7 @@
                 i = strlen(f->p.bar->buf);
                 p = f->p.bar->buf;
                 ixp_srv_writebuf(r, &p, &i, 279);
+ bar_load(f->p.bar);
                 r->ofcall.io.count = i - r->ifcall.io.offset;
                 respond(r, nil);
                 return;
@@ -664,8 +665,6 @@
 void
 fs_clunk(Ixp9Req *r) {
         IxpFileId *f;
- char *p, *q;
- IxpMsg m;
         
         f = r->fid->aux;
         if(!ixp_srv_verifyfile(f, lookup_file)) {
@@ -697,25 +696,6 @@
         case FsFKeys:
                 update_keys();
                 break;
- case FsFBar:
- p = f->p.bar->buf;
- m = ixp_message(p, strlen(p), 0);
- msg_parsecolors(&m, &f->p.bar->col);
-
- q = (char*)m.end-1;
- while(q >= (char*)m.pos && *q == '\n')
- *q-- = '\0';
-
- q = f->p.bar->text;
- utflcpy(q, (char*)m.pos, sizeof ((Bar*)0)->text);
-
- p[0] = '\0';
- strlcat(p, f->p.bar->col.colstr, sizeof(f->p.bar->buf));
- strlcat(p, " ", sizeof(f->p.bar->buf));
- strlcat(p, f->p.bar->text, sizeof(f->p.bar->buf));
-
- bar_draw(f->p.bar->screen);
- break;
         }
         respond(r, nil);
 }
Received on Thu May 21 2009 - 19:57:06 UTC

This archive was generated by hypermail 2.2.0 : Thu May 21 2009 - 20:00:06 UTC