PyXR

c:\projects\bitpim\src \ phones \ com_motov325m.py



0001 ### BITPIM
0002 ###
0003 ### Copyright (C) 2007 Joe Pham <djpham@bitpim.org>
0004 ###
0005 ### This program is free software; you can redistribute it and/or modify
0006 ### it under the terms of the BitPim license as detailed in the LICENSE file.
0007 ###
0008 ### $Id: com_motov325m.py 4563 2008-01-11 21:49:45Z djpham $
0009 
0010 """Communicate with Motorola phones using AT commands"""
0011 import time
0012 
0013 import common
0014 import com_motov3mm as v3mm
0015 import com_motov325 as v325
0016 import prototypes
0017 import p_motov325
0018 import helpids
0019 
0020 parentphone=v3mm.Phone
0021 class Phone(parentphone):
0022     """ Talk to a Motorola V3mM phone"""
0023     desc='Moto-V325M'
0024     helpid=helpids.ID_PHONE_MOTOV325M
0025     protocolclass=p_motov325
0026     serialsname='motov325m'
0027     MODEOBEX='modeobex'
0028 
0029     builtinringtones=(
0030         (0, ('Silent',)),
0031         (5, ('Vibe Dot', 'Vibe Dash', 'Vibe Dot Dot', 'Vibe Dot Dash',
0032              'Vibe Pulse')),
0033         (11, ('Alert', 'Standard', 'Bells', 'Triads', 'Up and Down')),
0034         (30, ('Moonlit Haze', 'Nightlife', 'Wind Chime', 'Random',
0035               'Bit & Bytes', 'Door Bell', 'Ding', 'One Moment', 'Provincial',
0036               'Harmonics', 'Interlude', 'Snaggle', 'Cosmic')),
0037         )
0038 
0039     def _get_del_new_list(self, index_key, media_key, merge, fundamentals,
0040                           origins):
0041         """Return a list of media being deleted and being added"""
0042         _index=fundamentals.get(index_key, {})
0043         _media=fundamentals.get(media_key, {})
0044         _index_file_list=[_entry['name'] for _entry in _index.values() \
0045                           if _entry.has_key('filename') and \
0046                           _entry['filename'].startswith(self.protocolclass.MOTO_SHARED_PATH) and \
0047                           _entry.get('origin', None) in origins ]
0048         _bp_file_list=[_entry['name'] for _entry in _media.values() \
0049                        if _entry.get('origin', None) in origins ]
0050         if merge:
0051             # just add the new files, don't delete anything
0052             _del_list=[]
0053             _new_list=_bp_file_list
0054         else:
0055             # Delete specified files and add everything
0056             _del_list=[x for x in _index_file_list if x not in _bp_file_list]
0057             _new_list=_bp_file_list
0058         return _del_list, _new_list
0059 
0060     def _add_files(self, index_key, media_key, media_path,
0061                    new_list, fundamentals):
0062         """Add new file using OBEX"""
0063         _index=fundamentals.get(index_key, {})
0064         _media=fundamentals.get(media_key, {})
0065         _adding_ringtones=index_key=='ringtone-index'
0066         for _file in new_list:
0067             _data=self._item_from_index(_file, 'data', _media)
0068             if not _data:
0069                 self.log('Failed to write file %s due to no data'%_file)
0070                 continue
0071             if self._item_from_index(_file, None, _index) is None:
0072                 # new file
0073                 _name=_file
0074                 if _adding_ringtones and \
0075                    common.getext(_name).lower()=='mp3':
0076                     # need to adjust the file name since this model only
0077                     # accepts qcp and mid files (AFAIK).
0078                     _name='%s.mid'%common.stripext(_name)
0079                 _file_name='%(pathname)s/%(filename)s'% \
0080                             { 'pathname': media_path,
0081                               'filename': _name }
0082                 try:
0083                     self.obex.writefile(_file_name, _data)
0084                 except:
0085                     self.log('Failed to write OBEX file '+_file_name)
0086                     if __debug__:
0087                         raise
0088         
0089     def getwallpapers(self, fundamentals):
0090         """Retrieve wallpaper data"""
0091         # The V325 needs some time to switch from BREW back to MODEM mode
0092         # without this sleep, the switch will always come back with ERROR
0093         self.log('Waiting for the phone to switch back to mode modem')
0094         time.sleep(2)
0095         self.setmode(self.MODEPHONEBOOK)
0096         return parentphone.getwallpapers(self, fundamentals)
0097 
0098     def getringtones(self, fundamentals):
0099         """Retrieve ringtones data"""
0100         self.log('Waiting for the phone to switch to MODEM')
0101         time.sleep(2)
0102         self.setmode(self.MODEPHONEBOOK)
0103         self.log('Reading ringtones')
0104         _res={}
0105         _rt_index=fundamentals.get('ringtone-index', {})
0106         # This model has ringtone files on both the normal dir (shared/audio)
0107         # as well as other dirs
0108         # 1st, get the BREW files
0109         self.setmode(self.MODEBREW)
0110         for _entry in _rt_index.values():
0111             if _entry.has_key('filename') and \
0112                not _entry['filename'].startswith(self.protocolclass.RT_PATH):
0113                 try:
0114                     _res[_entry['name']]=self.getfilecontents(_entry['filename'])
0115                 except:
0116                     self.log('Failed to read media file %s'%_entry['filename'])
0117         # Now, get the OBEX One        
0118         self.setmode(self.MODEOBEX)
0119         for _entry in _rt_index.values():
0120             if _entry.has_key('filename') and \
0121                _entry['filename'].startswith(self.protocolclass.RT_PATH):
0122                 try:
0123                     _res[_entry['name']]=self.obex.getfilecontents(
0124                         self.protocolclass.OBEXName(_entry['filename']))
0125                 except:
0126                     self.log('Failed to read media file %s'%_entry['filename'])
0127         fundamentals['ringtone']=_res
0128         self.setmode(self.MODEMODEM)
0129         # The phone will need to be reset (unplugged & replug) after this!
0130         fundamentals['clearcomm']=True
0131         return fundamentals
0132 
0133     def saveringtones(self, fundamentals, merge):
0134         """Save ringtones to the phone"""
0135         self.log('Waiting for the phone to switch back to mode modem')
0136         time.sleep(2)
0137         parentphone.saveringtones(self, fundamentals, merge)
0138         fundamentals['clearcomm']=True
0139         return fundamentals
0140 
0141     def savewallpapers(self, fundamentals, merge):
0142         """Save wallpapers to the phone"""
0143         self.log('Waiting for the phone to switch back to mode modem')
0144         time.sleep(2)
0145         self.log('Writing wallpapers to the phone')
0146         self.setmode(self.MODEBREW)
0147         try: 
0148             _del_list, _new_list=self._get_del_new_list('wallpaper-index',
0149                                                         'wallpapers',
0150                                                         merge,
0151                                                         fundamentals,
0152                                                         frozenset(['images']))
0153             # replace files
0154             self._replace_files('wallpaper-index', 'wallpapers',
0155                                 _new_list, fundamentals)
0156         except:
0157             if __debug__:
0158                 self.setmode(self.MODEMODEM)
0159                 raise
0160         self.setmode(self.MODEMODEM)
0161         return fundamentals
0162 
0163 
0164 #-------------------------------------------------------------------------------
0165 parentprofile=v325.Profile
0166 class Profile(parentprofile):
0167     serialsname=Phone.serialsname
0168     phone_model='V325M'
0169     generic_phone_model='Motorola V325M Phone'
0170 
0171     _supportedsyncs=(
0172         ('phonebook', 'read', None),  # all phonebook reading
0173         ('phonebook', 'write', 'OVERWRITE'),  # only overwriting phonebook
0174         ('calendar', 'read', None),   # all calendar reading
0175         ('calendar', 'write', 'OVERWRITE'),   # only overwriting calendar
0176         ('ringtone', 'read', None),   # all ringtone reading
0177         ('ringtone', 'read', 'EXCLUSIVE'),   # all ringtone reading
0178         ('ringtone', 'write', 'EXCLUSIVE'),
0179         ('ringtone', 'write', None),
0180         ('wallpaper', 'read', None),  # all wallpaper reading
0181         ('wallpaper', 'write', 'OVERWRITE'),
0182         ('sms', 'read', None),
0183         )
0184 

Generated by PyXR 0.9.4