bug in com_lglx5450.py

"Brent Roettger" <[email protected]>
Newsgroups gmane.comp.mobile.bitpim.devel
Message-ID <[email protected]>
Due to the fact that my phone detection routine is not working, I found a bug in the com_lglx5450.py file.

The eval_detect_data method uses an undefined variable named "found" on line 95.

I have attached an update source file and the exception that I was getting every time I would select "Detect Phone" from the menu.

Here is a fix for it where I default found to false.

def eval_detect_data(self, res):
found = False #this line is new
if res.get(self.brew_version_txt_key, None) is not None:
found=res[self.brew_version_txt_key][:len(self.my_version_txt)]==self.my_version_txt
if found:
res['model']=self.my_model
res['manufacturer']='LG Electronics
Inc'
s=res.get(self.esn_file_key, None)
if s:
res['esn']=self.get_esn(s)

This also brings up a good guestion. What is considered proper etiquette when finding a bug in someone else's code in BitPim?

I also think I found out why the code I have submitted was having extra line breaks. I am using Tortoise CVS and it has an option to "Use "Unix line endings". It is not marked by default. How does this file look?

Regards,

Brent Roettger
com_lglx5450.py (text/plain, 6.1 KB)
### BITPIM
###
### Copyright (C) 2003-2004 Roger Binns <[email protected]>
### Copyright (C) 2005 Simon Capper <[email protected]>
###
### This program is free software; you can redistribute it and/or modify
### it under the terms of the BitPim license as detailed in the LICENSE 
file.
###
### $Id: com_lglx5450.py,v 1.1 2005/11/15 07:20:14 skyjunky Exp $

"""Communicate with the LG LX5450 cell phone

The LX5450 is substantially similar to the VX4400 except that it supports 
more
image formats, has wallpapers in no less than 4 locations and puts things in
slightly different directories. It is almost identical to the vx6000.

The code in this file mainly inherits from VX4400 code and then extends 
where
the 5450 has extra functionality

"""

# standard modules
import time
import cStringIO
import sha

# my modules
import common
import copy
import p_lglx5450
import com_lgvx4400
import com_brew
import com_phone
import com_lg
import prototypes

class Phone(com_lgvx4400.Phone):
    "Talk to the LG LX5450 cell phone"

    desc="LG-LX5450"

    protocolclass=p_lglx5450
    serialsname='lglx5450'

    # more LX5450 indices
    imagelocations=(
        # offset, index file, files location, type, maximumentries
        ( 10, "download/dloadindex/brewImageIndex.map", "brew/shared", 
"images", 30) ,
        ( 0xc8, "download/dloadindex/mmsImageIndex.map", "brew/shared/mms", 
"mms", 20),
        ( 0xdc, "download/dloadindex/mmsDrmImageIndex.map", 
"brew/shared/mms/d", "drm", 20),
        ( 0x82, None, None, "camera", 20) # nb camera must be last
        )

    ringtonelocations=(
        # offset, index file, files location, type, maximumentries
        ( 50, "download/dloadindex/brewRingerIndex.map", 
"user/sound/ringer", "ringers", 30),
        ( 150, "download/dloadindex/mmsRingerIndex.map", "mms/sound", "mms", 
20),
        ( 180, "download/dloadindex/mmsDrmRingerIndex.map", "mms/sound/drm", 
"drm", 20)
        )

    builtinimages= ('Beach Ball', 'Towerbridge', 'Sunflower', 'Beach', 
'Fish',
                    'Sea', 'Snowman')

    builtinringtones= ('Ring 1', 'Ring 2', 'Ring 3', 'Ring 4', 'Ring 5', 
'Ring 6',
                       'Annen Polka', 'Beethoven Symphony No. 9', 'Pachelbel 
Canon',
                       'Hallelujah', 'La Traviata', 'Leichte Kavallerie 
Overture',
                       'Mozart Symphony No.40', 'Bach Minuet', 'Farewell',
                       'Mozart Piano Sonata', 'Sting', 'Trout', 'O solemio',
                       'Pizzicata Polka', 'Stars and Stripes Forever',
                       'Pineapple Rag', 'When the Saints Go Marching In', 
'Latin',
                       'Carol 1', 'Carol 2')


    def __init__(self, logtarget, commport):
        com_lgvx4400.Phone.__init__(self,logtarget,commport)
        self.mode=self.MODENONE

    def getcameraindex(self):
        buf=prototypes.buffer(self.getfilecontents("cam/pics.dat"))
        index={}
        g=self.protocolclass.campicsdat()
        g.readfrombuffer(buf)
        for i in g.items:
            if len(i.name):
                # index[i.index]={'name': i.name, 'date': i.taken, 'origin': 
'camera' }
                # we currently use the filesystem name rather than rename in 
camera
                # since the latter doesn't include the file extension which 
then makes
                # life less pleasant once the file ends up on the computer
                index[i.index]={'name': "pic%02d.jpg"%(i.index,), 'date': 
i.taken, 'origin': 'camera' }
        return index

    def eval_detect_data(self, res):
        found = False
        if res.get(self.brew_version_txt_key, None) is not None:
            
found=res[self.brew_version_txt_key][:len(self.my_version_txt)]==self.my_version_txt
        if found:
            res['model']=self.my_model
            res['manufacturer']='LG Electronics Inc'
            s=res.get(self.esn_file_key, None)
            if s:
                res['esn']=self.get_esn(s)


    my_version_txt='AX545V'
    my_model='LX5450'

parentprofile=com_lgvx4400.Profile
class Profile(parentprofile):
    protocolclass=Phone.protocolclass
    serialsname=Phone.serialsname
    phone_manufacturer='LG Electronics Inc'
    phone_model='LX5450'

    WALLPAPER_WIDTH=120
    WALLPAPER_HEIGHT=131
    MAX_WALLPAPER_BASENAME_LENGTH=32
    
WALLPAPER_FILENAME_CHARS="_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 
."
    WALLPAPER_CONVERT_FORMAT="bmp"

    MAX_RINGTONE_BASENAME_LENGTH=32
    
RINGTONE_FILENAME_CHARS="_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 
."

    # nb we don't allow save to camera so it isn't listed here
    imageorigins={}
    imageorigins.update(common.getkv(parentprofile.stockimageorigins, 
"images"))
    imageorigins.update(common.getkv(parentprofile.stockimageorigins, 
"mms"))
    imageorigins.update(common.getkv(parentprofile.stockimageorigins, 
"drm"))
    def GetImageOrigins(self):
        return self.imageorigins

    # our targets are the same for all origins
    imagetargets={}
    imagetargets.update(common.getkv(parentprofile.stockimagetargets, 
"wallpaper",
                                      {'width': 120, 'height': 131, 
'format': "BMP"}))

    def GetTargetsForImageOrigin(self, origin):
        return self.imagetargets

    _supportedsyncs=(
        ('sms', 'read', None),
        ('sms', 'write', 'OVERWRITE'),
        ('phonebook', 'read', None),  # all phonebook reading
        ('phonebook', 'write', 'OVERWRITE'),  # only overwriting phonebook
        ('calendar', 'write', 'OVERWRITE'),   # only overwriting calendar
        ('calendar', 'read', None),   # all calendar reading
        ('wallpaper', 'read', None),  # all wallpaper reading
        ('wallpaper', 'write', 'MERGE'),      # merge and overwrite 
wallpaper
        ('wallpaper', 'write', 'OVERWRITE'),
        ('ringtone', 'read', None),   # all ringtone reading
        ('ringtone', 'write', 'MERGE'),      # merge and overwrite ringtone
        ('ringtone', 'write', 'OVERWRITE'),
        ('memo', 'read', None),     # all memo list reading DJP
        ('memo', 'write', 'OVERWRITE'),  # all memo list writing DJP
        ('call_history', 'read', None),
       )

    def __init__(self):
        parentprofile.__init__(self)
exception.txt (text/plain, 4.6 KB)
An unexpected exception has occurred.
Please see the help for details on what to do.

Traceback (most recent call last):
  File "C:\SourceForge_Projects\bitpim\gui.py", line 174, in run
    res=call()
  File "C:\SourceForge_Projects\bitpim\gui.py", line 114, in __call__
    return apply(self.method, self.args+args, d)
  File "C:\SourceForge_Projects\bitpim\gui.py", line 1737, in detectphone
    return phone_detect.DetectPhone(self).detect(using_port)
  File "C:\SourceForge_Projects\bitpim\phone_detect.py", line 236, in detect
    self)
  File "C:\SourceForge_Projects\bitpim\com_lgvx4400.py", line 891, in 
detectphone
    p.eval_detect_data(res[port])
  File "C:\SourceForge_Projects\bitpim\com_lglx5450.py", line 95, in 
eval_detect_data
    if found:
UnboundLocalError: local variable 'found' referenced before assignment

Variables by last 8 frames, innermost last

Frame __bootstrap in C:\Python24\lib\threading.py at line 442
           self =  <WorkerThread(BitPim helper, started daemon)>

Frame run in C:\SourceForge_Projects\bitpim\gui.py at line 180
              e =  <exceptions.UnboundLocalError instance at 0x02B43A58>
            res =  None
           self =  <WorkerThread(BitPim helper, started daemon)>
           item =  (<gui.Request instance at 0x01EDC080>, <gui.Callback 
instance at 0x02792D50>)
           call =  <gui.Request instance at 0x01EDC080>
             ex =  <exceptions.UnboundLocalError instance at 0x02B43A58>
       resultcb =  <gui.Callback instance at 0x02792D50>
          first =  0

Frame __call__ in C:\SourceForge_Projects\bitpim\gui.py at line 114
           self =  <gui.Request instance at 0x01EDC080>
           args =  ()
              d =  Keys []
                   {}
         kwargs =  Keys []
                   {}

Frame detectphone in C:\SourceForge_Projects\bitpim\gui.py at line 1737
           self =  <WorkerThread(BitPim helper, started daemon)>
     using_port =  None

Frame detect in C:\SourceForge_Projects\bitpim\phone_detect.py at line 236
   likely_ports =  ['COM10']
              e =  'COM9'
         models =  ['Audiovox CDM-8900', 'LG-G4015 (AT&T)', 'LG-PM325 
(Sprint)', 'LG-TM520', 'LG-VX
     using_port =  None
           coms =  [{'available': False, 'driverdate': (2001, 7, 1), 
'description': 'Communications
     found_port =  None
              q =  'Done on port: COM9'
        threads =  [<Thread(Thread-1, stopped daemon)>]
              t =  <Thread(Thread-1, stopped daemon)>
    found_model =  None
              x =  Keys ['active', 'available', 'class', 'description', 
'driverdate', 'driverdescription', 'driverprovider', 'driverversion', 
'hardwareinstance', 'name']
                   {'available': False, 'driverdate': (2002, 4, 9), 
'description': 'Prolific USB-to
          model =  'LG-lX5450 (Alltel)'
             pm =  Keys ['Audiovox CDM-8900', 'LG-G4015 (AT&T)', 'LG-PM325 
(Sprint)', 'LG-TM520', 'LG-VX10', 'LG-VX3200', 'LG-VX4400', 'LG-VX4500', 
'LG-VX4600 (Telus Mobility)', 'LG-VX4650 (Verizon Wireless)', 'LG-VX5200 
(Verizon Wireless)', 'LG-VX6000', 'LG-VX6100', 'LG-VX7000', 'LG-VX8000 
(Verizon Wireless)', 'LG-VX8100 (Verizon Wireless)', 'LG-VX9800 (Verizon 
Wireless)', 'LG-lX5450 (Alltel)', 'MM-7400', 'MM-8300', 'Other CDMA phone', 
'PM-8200', 'RL-4920', 'SCH-A310', 'SCH-A650', 'SCH-A670', 'SCP-4900', 
'SCP-5300', 'SCP-5400', 'SCP-5500', 'SCP-7200', 'SCP-7300', 'SCP-8100', 
'SCP-8100 (Bell Mobility)', 'SK6100 (Pelephone)', 'SPH-A460', 'SPH-A620 
(VGA1000)', 'SPH-A740', 'SPH-N200']
                   {'LG-VX3200': 'com_lgvx3200', 'LG-VX9800 (Verizon 
Wireless)': 'com_lgvx9800', 'S
available_coms =  ['COM9', 'COM10']
           self =  <phone_detect.DetectPhone object at 0x02677D30>
available_modem_coms =  ['COM9']

Frame detectphone in C:\SourceForge_Projects\bitpim\com_lgvx4400.py at line 
895
            res =  Keys ['COM10', 'COM9']
                   {'COM9': {'mode_modem': True, 'mode_brew': False, 
'firmwareresponse': None, 'esn
           coms =  [{'available': False, 'driverdate': (2001, 7, 1), 
'description': 'Communications
              p =  <com_lglx5450.Phone instance at 0x02B43B20>
   likely_ports =  ['COM10']
           _log =  <phone_detect.DetectPhone object at 0x02677D30>
           port =  'COM10'

Frame eval_detect_data in C:\SourceForge_Projects\bitpim\com_lglx5450.py at 
line 95
            res =  Keys ['brew_version.txt', 'esn', 'esn_file', 
'firmware_version', 'firmwareresponse', 'lgpbinfo', 'manufacturer', 
'mode_brew', 'mode_modem', 'model']
                   {'mode_modem': None, 'esn_file': '193F6091', 'lgpbinfo': 
'\x00\x00\x00\x00\\\x00
           self =  <com_lglx5450.Phone instance at 0x02B43B20>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.