Package phones :: Module com_motov325m
[hide private]
[frames] | no frames]

Source Code for Module phones.com_motov325m

  1  ### BITPIM 
  2  ### 
  3  ### Copyright (C) 2007 Joe Pham <djpham@bitpim.org> 
  4  ### 
  5  ### This program is free software; you can redistribute it and/or modify 
  6  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  7  ### 
  8  ### $Id: com_motov325m.py 4563 2008-01-11 21:49:45Z djpham $ 
  9   
 10  """Communicate with Motorola phones using AT commands""" 
 11  import time 
 12   
 13  import common 
 14  import com_motov3mm as v3mm 
 15  import com_motov325 as v325 
 16  import prototypes 
 17  import p_motov325 
 18  import helpids 
 19   
 20  parentphone=v3mm.Phone 
21 -class Phone(parentphone):
22 """ Talk to a Motorola V3mM phone""" 23 desc='Moto-V325M' 24 helpid=helpids.ID_PHONE_MOTOV325M 25 protocolclass=p_motov325 26 serialsname='motov325m' 27 MODEOBEX='modeobex' 28 29 builtinringtones=( 30 (0, ('Silent',)), 31 (5, ('Vibe Dot', 'Vibe Dash', 'Vibe Dot Dot', 'Vibe Dot Dash', 32 'Vibe Pulse')), 33 (11, ('Alert', 'Standard', 'Bells', 'Triads', 'Up and Down')), 34 (30, ('Moonlit Haze', 'Nightlife', 'Wind Chime', 'Random', 35 'Bit & Bytes', 'Door Bell', 'Ding', 'One Moment', 'Provincial', 36 'Harmonics', 'Interlude', 'Snaggle', 'Cosmic')), 37 ) 38
39 - def _get_del_new_list(self, index_key, media_key, merge, fundamentals, 40 origins):
41 """Return a list of media being deleted and being added""" 42 _index=fundamentals.get(index_key, {}) 43 _media=fundamentals.get(media_key, {}) 44 _index_file_list=[_entry['name'] for _entry in _index.values() \ 45 if _entry.has_key('filename') and \ 46 _entry['filename'].startswith(self.protocolclass.MOTO_SHARED_PATH) and \ 47 _entry.get('origin', None) in origins ] 48 _bp_file_list=[_entry['name'] for _entry in _media.values() \ 49 if _entry.get('origin', None) in origins ] 50 if merge: 51 # just add the new files, don't delete anything 52 _del_list=[] 53 _new_list=_bp_file_list 54 else: 55 # Delete specified files and add everything 56 _del_list=[x for x in _index_file_list if x not in _bp_file_list] 57 _new_list=_bp_file_list 58 return _del_list, _new_list
59
60 - def _add_files(self, index_key, media_key, media_path, 61 new_list, fundamentals):
62 """Add new file using OBEX""" 63 _index=fundamentals.get(index_key, {}) 64 _media=fundamentals.get(media_key, {}) 65 _adding_ringtones=index_key=='ringtone-index' 66 for _file in new_list: 67 _data=self._item_from_index(_file, 'data', _media) 68 if not _data: 69 self.log('Failed to write file %s due to no data'%_file) 70 continue 71 if self._item_from_index(_file, None, _index) is None: 72 # new file 73 _name=_file 74 if _adding_ringtones and \ 75 common.getext(_name).lower()=='mp3': 76 # need to adjust the file name since this model only 77 # accepts qcp and mid files (AFAIK). 78 _name='%s.mid'%common.stripext(_name) 79 _file_name='%(pathname)s/%(filename)s'% \ 80 { 'pathname': media_path, 81 'filename': _name } 82 try: 83 self.obex.writefile(_file_name, _data) 84 except: 85 self.log('Failed to write OBEX file '+_file_name) 86 if __debug__: 87 raise
88
89 - def getwallpapers(self, fundamentals):
90 """Retrieve wallpaper data""" 91 # The V325 needs some time to switch from BREW back to MODEM mode 92 # without this sleep, the switch will always come back with ERROR 93 self.log('Waiting for the phone to switch back to mode modem') 94 time.sleep(2) 95 self.setmode(self.MODEPHONEBOOK) 96 return parentphone.getwallpapers(self, fundamentals)
97
98 - def getringtones(self, fundamentals):
99 """Retrieve ringtones data""" 100 self.log('Waiting for the phone to switch to MODEM') 101 time.sleep(2) 102 self.setmode(self.MODEPHONEBOOK) 103 self.log('Reading ringtones') 104 _res={} 105 _rt_index=fundamentals.get('ringtone-index', {}) 106 # This model has ringtone files on both the normal dir (shared/audio) 107 # as well as other dirs 108 # 1st, get the BREW files 109 self.setmode(self.MODEBREW) 110 for _entry in _rt_index.values(): 111 if _entry.has_key('filename') and \ 112 not _entry['filename'].startswith(self.protocolclass.RT_PATH): 113 try: 114 _res[_entry['name']]=self.getfilecontents(_entry['filename']) 115 except: 116 self.log('Failed to read media file %s'%_entry['filename']) 117 # Now, get the OBEX One 118 self.setmode(self.MODEOBEX) 119 for _entry in _rt_index.values(): 120 if _entry.has_key('filename') and \ 121 _entry['filename'].startswith(self.protocolclass.RT_PATH): 122 try: 123 _res[_entry['name']]=self.obex.getfilecontents( 124 self.protocolclass.OBEXName(_entry['filename'])) 125 except: 126 self.log('Failed to read media file %s'%_entry['filename']) 127 fundamentals['ringtone']=_res 128 self.setmode(self.MODEMODEM) 129 # The phone will need to be reset (unplugged & replug) after this! 130 fundamentals['clearcomm']=True 131 return fundamentals
132
133 - def saveringtones(self, fundamentals, merge):
134 """Save ringtones to the phone""" 135 self.log('Waiting for the phone to switch back to mode modem') 136 time.sleep(2) 137 parentphone.saveringtones(self, fundamentals, merge) 138 fundamentals['clearcomm']=True 139 return fundamentals
140
141 - def savewallpapers(self, fundamentals, merge):
142 """Save wallpapers to the phone""" 143 self.log('Waiting for the phone to switch back to mode modem') 144 time.sleep(2) 145 self.log('Writing wallpapers to the phone') 146 self.setmode(self.MODEBREW) 147 try: 148 _del_list, _new_list=self._get_del_new_list('wallpaper-index', 149 'wallpapers', 150 merge, 151 fundamentals, 152 frozenset(['images'])) 153 # replace files 154 self._replace_files('wallpaper-index', 'wallpapers', 155 _new_list, fundamentals) 156 except: 157 if __debug__: 158 self.setmode(self.MODEMODEM) 159 raise 160 self.setmode(self.MODEMODEM) 161 return fundamentals
162 163 164 #------------------------------------------------------------------------------- 165 parentprofile=v325.Profile
166 -class Profile(parentprofile):
167 serialsname=Phone.serialsname 168 phone_model='V325M' 169 generic_phone_model='Motorola V325M Phone' 170 171 _supportedsyncs=( 172 ('phonebook', 'read', None), # all phonebook reading 173 ('phonebook', 'write', 'OVERWRITE'), # only overwriting phonebook 174 ('calendar', 'read', None), # all calendar reading 175 ('calendar', 'write', 'OVERWRITE'), # only overwriting calendar 176 ('ringtone', 'read', None), # all ringtone reading 177 ('ringtone', 'read', 'EXCLUSIVE'), # all ringtone reading 178 ('ringtone', 'write', 'EXCLUSIVE'), 179 ('ringtone', 'write', None), 180 ('wallpaper', 'read', None), # all wallpaper reading 181 ('wallpaper', 'write', 'OVERWRITE'), 182 ('sms', 'read', None), 183 )
184