Changeset 1809
- Timestamp:
- 02/24/07 07:01:29 (22 months ago)
- Location:
- plugins/moto-sync
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
plugins/moto-sync/README
r1794 r1809 6 6 mess up the data on your phone and any other members of the sync group, 7 7 due to the limited data that can be stored on the phone. Use with caution 8 and make backups! 9 10 To prevent it writing any changes to the phone, set WRITE_ENABLED to False 11 (near the top of the file). Note that this will still allow it to send data 12 back to the other members of the sync group, so you probably want to have 13 backups of everything anyway. See TESTING/BACKUP below. 8 and make backups! See TESTING/BACKUP below. 14 9 15 10 … … 85 80 TESTING/BACKUP 86 81 87 Before doing anything with write enabled, it is probably a good idea to88 backup the data from your phone. You can use the mototool script to 89 d o this, and to delete entries on the phone. Run 'mototool --help'for90 details, or, forthe impatient, try:91 mototool - v -d (device string) -f myphone.backup --backup82 Before doing anything, it is probably a good idea to backup the data 83 from your phone. You can use the mototool script to do this, and to 84 delete entries on the phone. Run 'mototool --help' for details, or, for 85 the impatient, try: 86 mototool -d (device string) -f myphone.backup --backup 92 87 93 88 -
plugins/moto-sync/motosync.py
r1807 r1809 12 12 __revision__ = "$Id$" 13 13 14 import sys,os, types, md5, time, calendar, re14 import os, types, md5, time, calendar, re 15 15 import xml.dom.minidom 16 16 from datetime import date, datetime, timedelta, time as datetime_time … … 32 32 USE_BLUETOOTH_MODULE = False 33 33 34 # debug/test options:35 DEBUG_OUTPUT = False # if enabled, logs all interaction with the phone to stdout36 WARNING_OUTPUT = True # if enabled, prints warnings to stderr (reccommended)37 WRITE_ENABLED = True # if disabled, prevents changes from being made to phone38 34 39 35 # Regular expression for a Bluetooth MAC address … … 174 170 RRULE_FUTURE = timedelta(365) # 1 year 175 171 176 177 def debug(msg):178 """Print a debug message, if enabled."""179 if DEBUG_OUTPUT:180 sys.stdout.write("moto-sync: " + msg + "\n")181 182 def warning(msg):183 """Print a warning message, if enabled."""184 if WARNING_OUTPUT:185 sys.stderr.write("moto-sync: Warning: " + msg + "\n")186 172 187 173 def getElementsByTagNames(parent, tagnames, ret): … … 452 438 tty.setraw(self.__fd) 453 439 else: 454 warning('tty module not present, unable to set raw mode')440 opensync.trace(opensync.TRACE_INTERNAL, 'tty module not present, unable to set raw mode') 455 441 456 442 # reset the phone and send it a bunch of init strings … … 580 566 data = evdata[:-1] 581 567 placeholders = self.__make_placeholders(data) 582 self.__do_cmd(('AT+MDBW=' + placeholders) % tuple(data) , WRITE_ENABLED)568 self.__do_cmd(('AT+MDBW=' + placeholders) % tuple(data)) 583 569 for expos in exceptions: 584 self.__do_cmd('AT+MDBWE=%d,%d,1' % (pos, expos) , WRITE_ENABLED)570 self.__do_cmd('AT+MDBWE=%d,%d,1' % (pos, expos)) 585 571 586 572 def delete_event(self, pos): 587 573 """delete the event at a specific position""" 588 574 self.open_calendar() 589 self.__do_cmd('AT+MDBWE=%d,0,0' % pos , WRITE_ENABLED)575 self.__do_cmd('AT+MDBWE=%d,0,0' % pos) 590 576 591 577 def read_categories(self): … … 662 648 self.close_calendar() 663 649 placeholders = self.__make_placeholders(data) 664 self.__do_cmd(('AT+MPBW=' + placeholders) % tuple(data) , WRITE_ENABLED)650 self.__do_cmd(('AT+MPBW=' + placeholders) % tuple(data)) 665 651 666 652 def delete_contact(self, pos): 667 653 """delete the contact at a given position""" 668 654 self.close_calendar() 669 self.__do_cmd('AT+MPBW=%d' % pos , WRITE_ENABLED)655 self.__do_cmd('AT+MPBW=%d' % pos) 670 656 671 657 def __readchar(self): … … 685 671 ret += c 686 672 c = self.__readchar() 687 debug('<-- ' + ret)673 opensync.trace(opensync.TRACE_SENSITIVE, '<-- ' + ret) 688 674 if c == '': # EOF, shouldn't happen 689 675 raise opensync.Error('Unexpected EOF talking to phone', opensync.ERROR_IO_ERROR) 690 676 return ret 691 677 692 def __do_cmd(self, cmd , reallydoit=True):678 def __do_cmd(self, cmd): 693 679 """Send a command to the phone and wait for its response. 694 680 … … 696 682 """ 697 683 cmd = cmd.encode('iso_8859_1') 698 debug('--> ' + cmd)684 opensync.trace(opensync.TRACE_SENSITIVE, '--> ' + cmd) 699 685 ret = [] 700 if reallydoit: 701 cmd = cmd + '\r' 702 if self.__fd: 703 os.write(self.__fd, cmd) 704 elif self.__btsock: 705 self.__btsock.send(cmd) 706 line = self.__readline() 707 else: 708 line = 'OK' 686 cmd = cmd + '\r' 687 if self.__fd: 688 os.write(self.__fd, cmd) 689 elif self.__btsock: 690 self.__btsock.send(cmd) 691 line = self.__readline() 709 692 while line != 'OK' and line != 'ERROR': 710 693 ret.append(line) … … 1644 1627 return True 1645 1628 1646 def update_entry(self, change ):1629 def update_entry(self, change, context): 1647 1630 """Update an entry or add a new one, from the OSyncChange object. 1648 1631 … … 1658 1641 entry = PhoneContactXML(change.data.data, self.revcategories) 1659 1642 except UnsupportedDataError, e: 1660 warning("%s is unsupported (%s), ignored" % (change.uid, str(e))) 1643 err = opensync.Error("%s is unsupported (%s), ignored" % (change.uid, str(e)), opensync.ERROR_NOT_SUPPORTED) 1644 context.report_osyncwarning(err) 1661 1645 # we have an entry that can't be stored on the phone 1662 1646 # if its modified and we've seen it before, delete it … … 1782 1766 elif change.changetype == opensync.CHANGE_TYPE_MODIFIED: 1783 1767 old_uid = change.uid 1784 success = self.access.update_entry(change )1768 success = self.access.update_entry(change, ctx) 1785 1769 # if the UID has changed, we need to tell our hashtable that 1786 1770 # the old one was deleted, to keep it consistent … … 1788 1772 self.hashtable.update_hash(opensync.CHANGE_TYPE_DELETED, old_uid, None) 1789 1773 else: 1790 success = self.access.update_entry(change )1774 success = self.access.update_entry(change, ctx) 1791 1775 if success: 1792 1776 self.hashtable.update_hash(change.changetype, change.uid, change.hash) -
plugins/moto-sync/mototool
r1794 r1809 31 31 p.add_option('-d', '--device', dest='device', 32 32 help='device to access phone, defaults to %s' % DEFAULT_DEVICE) 33 p.add_option('-v', '--verbose', action='store_true', dest='verbose',34 help='log phone commands to stdout')35 33 p.add_option('-t', '--type', action='append', dest='objtype', 36 34 choices=motosync.SUPPORTED_OBJTYPES, … … 44 42 p.add_option('--delete', action='store_const', dest='mode', const='delete', 45 43 help='delete all entries on the phone') 46 p.set_defaults(device=DEFAULT_DEVICE, verbose=False, filename=None, 47 mode=None, objtype=None) 44 p.set_defaults(device=DEFAULT_DEVICE, filename=None, mode=None, objtype=None) 48 45 options, args = p.parse_args() 49 46 if not options.mode: … … 56 53 """Prompt the user if they are trying to write to the phone.""" 57 54 if options.mode == 'delete' or options.mode == 'restore': 58 if not motosync.WRITE_ENABLED: 59 print 'WARNING: writes disabled, this will not save/delete anything' 60 else: 61 print ('WARNING: About to %s all %s entries from the phone!' 62 % (options.mode, ' & '.join(options.objtype))) 55 print ('WARNING: About to %s all %s entries from the phone!' 56 % (options.mode, ' & '.join(options.objtype))) 63 57 print 'Are you sure? [yn] ', 64 58 if sys.stdin.read(1).lower() != 'y': … … 107 101 if not options.objtype: 108 102 options.objtype = motosync.SUPPORTED_OBJTYPES 109 motosync.DEBUG_OUTPUT = options.verbose110 103 111 104 prompt_user(options)
