Hi Peter -

Your change does improve things. 'list' no longer includes the entire contents 
of the 'directory' but only the subdirectories as desired. However 'list' is 
still a list, cannot be split, and the same error occurs. I figured out how to 
get around that by converting the list to a string (see below usage of 
namelist), and discovered some other problems along the way. Seems as if 
branch_path was being used instead of branch_entry in a couple of places. 
Please review the code fragment below:

        if self._type == 'DS2409':
            for branch in names:
                path = self._usePath + '/' + branch
                #list = filter(lambda x: '/' in x, 
self._connection.dir(self._usePath))
                list = filter(lambda x: '/' in x, self._connection.dir(path))
                if list:
                    namelist = ', '.join(list)
                    #print 'namelist(%s)' % str(namelist)
                    for branch_entry in namelist.split(','):
                        branch_path = self._usePath + '/' + branch + '/' + 
branch_entry.split('/')[0]
                        #print 'branch_entry(%s)' % str(branch_entry)
                        #print 'branch_path(%s)' % str(branch_path)
                        try:
                            #self._connection.read(branch_path + '/type')
                            self._connection.read(branch_entry + '/type')
                        except exUnknownSensor, ex:
                            continue
                        #yield Sensor(branch_path, connection=self._connection)
                        yield Sensor(branch_entry, connection=self._connection)

r.sensorList() now yields results such as:
[Sensor("/1F.4CD000000000/main/26.797422000000", server="127.0.0.1", 
port=3002), Sensor("/1F.4CD000000000/aux/26.1D6E0D000000", server="127.0.0.1", 
port=3002)]
>>> 

That looks correct, and nothing else seems broken, although further testing is 
of course required. In the process of working with all of this, I did expose 
another problem. If the 2409 has a branch that is empty, connection.unpack is 
passed an empty argument resulting in:

Connection.dir("/1F.A6D500000000/aux")
Connection.unpack("")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/opt/local/lib/python2.4/site-packages/ownet/__init__.py", line 422, in 
sensorList
    return [s for s in self.sensors()]
  File "/opt/local/lib/python2.4/site-packages/ownet/__init__.py", line 377, in 
sensors
    list = filter(lambda x: '/' in x, self._connection.dir(path))
  File "/opt/local/lib/python2.4/site-packages/ownet/connection.py", line 163, 
in dir
    ret, payload_len, data_len = self.unpack(data)
  File "/opt/local/lib/python2.4/site-packages/ownet/connection.py", line 195, 
in unpack
    val          = struct.unpack('iiiiii', msg)
struct.error: unpack str size does not match format
>>> 

You can fix this by adding an 'if not data: break' statement:

        while 1:
            data = s.recv(24)
            if not data: break

            ret, payload_len, data_len = self.unpack(data)
            if payload_len:
                data = s.recv(payload_len)
                fields.append(data[:data_len])
            else:
                break
        s.close()
        return fields

So far, this does not seem to result in any other ill effects.

Hope this all makes sense. I still have a lot to learn :)

Ziggy

On Sun, 24 Dec 2006 06:38:22 -0800, "Peter Kropf" <[EMAIL PROTECTED]> wrote:
> On 12/24/06, Peter Kropf <[EMAIL PROTECTED]> wrote:
>> On 12/23/06, ziggy <[EMAIL PROTECTED]> wrote:
>> >
>> > I'm trying to work with the recently released ownet python classes
> (ownet-0.2). This is on an unslung Slug (6.8) if it matters. I am running
> into a problem when trying to traverse a 2409 swtich. Now, part of the
> problem may be that I learning python at the same time, so please forgive
> me if I am barking up the wrong tree. Please see below:
>> >
>> > # python
>> > Python 2.4.4 (#1, Nov  8 2006, 11:28:40)
>> > [GCC 3.3.5] on linux2
>> > Type "help", "copyright", "credits" or "license" for more information.
>> > >>> import ownet
>> >
>> > >>> r
>> > Sensor("/1F.A6D500000000", server="127.0.0.1", port=3002)
>> > >>> s=r.sensorList()
>> > Sensor.sensorList(['main', 'aux'])
>> > Sensor.sensors(['main', 'aux'])
>> > Traceback (most recent call last):
>> >   File "<stdin>", line 1, in ?
>> >   File "/opt/local/lib/python2.4/site-packages/ownet/__init__.py",
> line 415, in sensorList
>> >     return [s for s in self.sensors()]
>> >   File "/opt/local/lib/python2.4/site-packages/ownet/__init__.py",
> line 378, in sensors
>> >     for branch_entry in list.split(','):
>> > AttributeError: 'list' object has no attribute 'split'
>> > >>>
>> >
>> > (For debugging purposes, I uncommented the two print statements, hence
> the two lines showing the list ['main', 'aux'].)
>> >
>> > The problem with line 378 is due to line 376:
>> >
>> > list = filter(lambda x: '/' in x, self._connection.dir(self._usePath))
>> >
>> > list is a list returned by filter, and split is a string method, thus
> the error. I'll work on fixing this, but someone that is truly python
> literate should probably do the official patch/fix. Any insights or
> instruction would be appreciated. Thanks!
>>
>> Hi Ziggy -
>>
>> I'm currently traveling for the holidays and as such, I don't have any
>> 1-wire devices or bridges with me. (Yeah, I know. What kind of a ow
>> developer am I, traveling without any 1-wire devices ;-) But when I
>> get back home, I'll take a look at what's going on and see about
>> fixing it...
>>
>> - Peter
>>
> 
> 
> Looking at the code quickly, the
> 
>                 list = filter(lambda x: '/' in x,
> self._connection.dir(self._usePath))
> 
> line looks wrong.  Can you try changing it to:
> 
>                 list = filter(lambda x: '/' in x,
> self._connection.dir(path))
> 
> so that it'll use the path as defined on the line above it?
> 
> I'm not able to test this right now so it may or may not work...
> 
> - Peter
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Owfs-developers mailing list
> Owfs-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/owfs-developers


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Owfs-developers mailing list
Owfs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to