def save_media(self, result, dl_info): self.__phone.log('Saving media for type '+self.__file_type) media, idx=result[self.__file_type], result[self.__index_type] media_names=[media[k]['name'] for k in media] dl_info_keys=dl_info.keys() deleted_keys=[k for k in dl_info_keys if k not in media_names] new_keys=[k for k in media if media[k]['name'] not in dl_info_keys] campix_file_path=self.__phone.protocolclass.cam_pix_file_path campix_file_len=len(campix_file_path) for k in deleted_keys: file_name=dl_info[k] if file_name[:campix_file_len]==campix_file_path: continue self.__phone.log('Deleting file: '+file_name) try: self.__phone.rmfile(file_name) except: self.__phone.log('Failed to delete file: '+file_name) if len(new_keys): try: self.__phone.mkdirs(self.__path) self.__phone.mkdirs('brew/shared') except: pass file_count=0 for k in new_keys: n=media[k] origin=n.get('origin', None) if origin is not None and origin != self.__origin: continue if len(n['name']) > self.__max_file_len: self.__phone.log('%s %s name is too long and not sent to phone'% \ (self.__file_type, n['name'])) continue file_count+=1 if file_count>self.__max_file_count: self.__phone.log('This phone only supports %d %s. Save operation stopped.'%\ (self.__max_file_count, self.__file_type)) break if self.__origin=='images': file_info=fileinfo.identify_imagestring(n['data']) if file_info.format in ('JPEG', 'GIF', 'BMP'): (mms_file_name, file_hdr)=\ getattr(self, '_to_mms_'+file_info.format)( n['name'], len(n['data'])) file_name=self.__path+'/'+mms_file_name file_contents=file_hdr+n['data'] elif file_info.format=='PNG': file_name='brew/shared/'+n['name'] file_contents=conversions.convertto8bitpng_joe(n['data']) else: continue else: file_name=self.__path+'/'+n['name'] file_contents=n['data'] self.__phone.log('Writing file: '+file_name) try: self.__phone.writefile(file_name, file_contents) except: self.__phone.log('Failed to write file: '+file_name) media[k]['origin']=self.__origin return result
def GetFileInfoString(self, string): return fileinfo.identify_imagestring(string)
def save_media(self, result, dl_info): self.__phone.log('Saving media for type ' + self.__file_type) media, idx = result[self.__file_type], result[self.__index_type] # check for files selected for deletion media_names = [media[k]['name'] for k in media] dl_info_keys = dl_info.keys() deleted_keys = [k for k in dl_info_keys if k not in media_names] new_keys = [k for k in media if media[k]['name'] not in dl_info_keys] # deleting files campix_file_path = self.__phone.protocolclass.cam_pix_file_path campix_file_len = len(campix_file_path) for k in deleted_keys: file_name = dl_info[k] if file_name[:campix_file_len] == campix_file_path: # campera pix, do nothing continue self.__phone.log('Deleting file: ' + file_name) try: self.__phone.rmfile(file_name) except: self.__phone.log('Failed to delete file: ' + file_name) # writing new files # make sure dir exists to write new files if len(new_keys): try: self.__phone.mkdirs(self.__path) # yet another hack self.__phone.mkdirs('brew/shared') except: pass file_count = 0 for k in new_keys: n = media[k] origin = n.get('origin', None) if origin is not None and origin != self.__origin: continue if len(n['name']) > self.__max_file_len: self.__phone.log('%s %s name is too long and not sent to phone'% \ (self.__file_type, n['name'])) continue file_count += 1 if file_count > self.__max_file_count: # max # of files reached, bailing out self.__phone.log('This phone only supports %d %s. Save operation stopped.'%\ (self.__max_file_count, self.__file_type)) break if self.__origin == 'images': file_info = fileinfo.identify_imagestring(n['data']) if file_info.format in ('JPEG', 'GIF', 'BMP'): # jpeg/gif/bmp file/picture ID files (mms_file_name, file_hdr)=\ getattr(self, '_to_mms_'+file_info.format)( n['name'], len(n['data'])) file_name = self.__path + '/' + mms_file_name file_contents = file_hdr + n['data'] elif file_info.format == 'PNG': # wallpaper files file_name = 'brew/shared/' + n['name'] # try to optimize png image files file_contents = conversions.convertto8bitpng_joe(n['data']) else: # unknown file type, skip it continue else: file_name = self.__path + '/' + n['name'] file_contents = n['data'] self.__phone.log('Writing file: ' + file_name) try: self.__phone.writefile(file_name, file_contents) except: self.__phone.log('Failed to write file: ' + file_name) media[k]['origin'] = self.__origin return result
def save_media(self, result, dl_info): self.__phone.log('Saving media for type '+self.__file_type) media, idx=result[self.__file_type], result[self.__index_type] # check for files selected for deletion media_names=[media[k]['name'] for k in media] dl_info_keys=dl_info.keys() deleted_keys=[k for k in dl_info_keys if k not in media_names] new_keys=[k for k in media if media[k]['name'] not in dl_info_keys] # deleting files campix_file_path=self.__phone.protocolclass.cam_pix_file_path campix_file_len=len(campix_file_path) for k in deleted_keys: file_name=dl_info[k] if file_name[:campix_file_len]==campix_file_path: # campera pix, do nothing continue self.__phone.log('Deleting file: '+file_name) try: self.__phone.rmfile(file_name) except: self.__phone.log('Failed to delete file: '+file_name) # writing new files # make sure dir exists to write new files if len(new_keys): try: self.__phone.mkdirs(self.__path) # yet another hack self.__phone.mkdirs('brew/shared') except: pass file_count=0 for k in new_keys: n=media[k] origin=n.get('origin', None) if origin is not None and origin != self.__origin: continue if len(n['name']) > self.__max_file_len: self.__phone.log('%s %s name is too long and not sent to phone'% \ (self.__file_type, n['name'])) continue file_count+=1 if file_count>self.__max_file_count: # max # of files reached, bailing out self.__phone.log('This phone only supports %d %s. Save operation stopped.'%\ (self.__max_file_count, self.__file_type)) break if self.__origin=='images': file_info=fileinfo.identify_imagestring(n['data']) if file_info.format in ('JPEG', 'GIF', 'BMP'): # jpeg/gif/bmp file/picture ID files (mms_file_name, file_hdr)=\ getattr(self, '_to_mms_'+file_info.format)( n['name'], len(n['data'])) file_name=self.__path+'/'+mms_file_name file_contents=file_hdr+n['data'] elif file_info.format=='PNG': # wallpaper files file_name='brew/shared/'+n['name'] # try to optimize png image files file_contents=conversions.convertto8bitpng_joe(n['data']) else: # unknown file type, skip it continue else: file_name=self.__path+'/'+n['name'] file_contents=n['data'] self.__phone.log('Writing file: '+file_name) try: self.__phone.writefile(file_name, file_contents) except: self.__phone.log('Failed to write file: '+file_name) media[k]['origin']=self.__origin return result