Changeset 1809

Show
Ignore:
Timestamp:
02/24/07 07:01:29 (22 months ago)
Author:
abaumann
Message:

cleanup:

  • remove DEBUG/WARNING options from motosync source, and replace them with calls to opensync's tracing and warning functions
  • remove WRITE_ENABLED option, since you can screw the data on the PC side without it anyway, and mototool lets you make and restore a backup of the phone
Location:
plugins/moto-sync
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • plugins/moto-sync/README

    r1794 r1809  
    66mess up the data on your phone and any other members of the sync group, 
    77due 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. 
     8and make backups! See TESTING/BACKUP below. 
    149 
    1510 
     
    8580TESTING/BACKUP 
    8681 
    87 Before doing anything with write enabled, it is probably a good idea to 
    88 backup the data from your phone. You can use the mototool script to 
    89 do this, and to delete entries on the phone. Run 'mototool --help' for  
    90 details, or, for the impatient, try: 
    91     mototool -v -d (device string) -f myphone.backup --backup 
     82Before doing anything, it is probably a good idea to backup the data  
     83from your phone. You can use the mototool script to do this, and to  
     84delete entries on the phone. Run 'mototool --help' for details, or, for  
     85the impatient, try: 
     86    mototool -d (device string) -f myphone.backup --backup 
    9287 
    9388 
  • plugins/moto-sync/motosync.py

    r1807 r1809  
    1212__revision__ = "$Id$" 
    1313 
    14 import sys, os, types, md5, time, calendar, re 
     14import os, types, md5, time, calendar, re 
    1515import xml.dom.minidom 
    1616from datetime import date, datetime, timedelta, time as datetime_time 
     
    3232    USE_BLUETOOTH_MODULE = False 
    3333 
    34 # debug/test options: 
    35 DEBUG_OUTPUT = False # if enabled, logs all interaction with the phone to stdout 
    36 WARNING_OUTPUT = True # if enabled, prints warnings to stderr (reccommended) 
    37 WRITE_ENABLED = True # if disabled, prevents changes from being made to phone 
    3834 
    3935# Regular expression for a Bluetooth MAC address 
     
    174170RRULE_FUTURE = timedelta(365) # 1 year 
    175171 
    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") 
    186172 
    187173def getElementsByTagNames(parent, tagnames, ret): 
     
    452438                tty.setraw(self.__fd) 
    453439            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') 
    455441 
    456442        # reset the phone and send it a bunch of init strings 
     
    580566        data = evdata[:-1] 
    581567        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)) 
    583569        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)) 
    585571 
    586572    def delete_event(self, pos): 
    587573        """delete the event at a specific position""" 
    588574        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) 
    590576 
    591577    def read_categories(self): 
     
    662648        self.close_calendar() 
    663649        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)) 
    665651 
    666652    def delete_contact(self, pos): 
    667653        """delete the contact at a given position""" 
    668654        self.close_calendar() 
    669         self.__do_cmd('AT+MPBW=%d' % pos, WRITE_ENABLED) 
     655        self.__do_cmd('AT+MPBW=%d' % pos) 
    670656 
    671657    def __readchar(self): 
     
    685671            ret += c 
    686672            c = self.__readchar() 
    687         debug('<-- ' + ret) 
     673        opensync.trace(opensync.TRACE_SENSITIVE, '<-- ' + ret) 
    688674        if c == '': # EOF, shouldn't happen 
    689675            raise opensync.Error('Unexpected EOF talking to phone', opensync.ERROR_IO_ERROR) 
    690676        return ret 
    691677 
    692     def __do_cmd(self, cmd, reallydoit=True): 
     678    def __do_cmd(self, cmd): 
    693679        """Send a command to the phone and wait for its response. 
    694680 
     
    696682        """ 
    697683        cmd = cmd.encode('iso_8859_1') 
    698         debug('--> ' + cmd) 
     684        opensync.trace(opensync.TRACE_SENSITIVE, '--> ' + cmd) 
    699685        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() 
    709692        while line != 'OK' and line != 'ERROR': 
    710693            ret.append(line) 
     
    16441627        return True 
    16451628 
    1646     def update_entry(self, change): 
     1629    def update_entry(self, change, context): 
    16471630        """Update an entry or add a new one, from the OSyncChange object. 
    16481631         
     
    16581641                entry = PhoneContactXML(change.data.data, self.revcategories) 
    16591642        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) 
    16611645            # we have an entry that can't be stored on the phone 
    16621646            # if its modified and we've seen it before, delete it 
     
    17821766        elif change.changetype == opensync.CHANGE_TYPE_MODIFIED: 
    17831767            old_uid = change.uid 
    1784             success = self.access.update_entry(change) 
     1768            success = self.access.update_entry(change, ctx) 
    17851769            # if the UID has changed, we need to tell our hashtable that 
    17861770            # the old one was deleted, to keep it consistent 
     
    17881772                self.hashtable.update_hash(opensync.CHANGE_TYPE_DELETED, old_uid, None) 
    17891773        else: 
    1790             success = self.access.update_entry(change) 
     1774            success = self.access.update_entry(change, ctx) 
    17911775        if success: 
    17921776            self.hashtable.update_hash(change.changetype, change.uid, change.hash) 
  • plugins/moto-sync/mototool

    r1794 r1809  
    3131    p.add_option('-d', '--device', dest='device', 
    3232                 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') 
    3533    p.add_option('-t', '--type', action='append', dest='objtype', 
    3634                 choices=motosync.SUPPORTED_OBJTYPES, 
     
    4442    p.add_option('--delete', action='store_const', dest='mode', const='delete', 
    4543                 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) 
    4845    options, args = p.parse_args() 
    4946    if not options.mode: 
     
    5653    """Prompt the user if they are trying to write to the phone.""" 
    5754    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))) 
    6357        print 'Are you sure? [yn] ', 
    6458        if sys.stdin.read(1).lower() != 'y': 
     
    107101    if not options.objtype: 
    108102        options.objtype = motosync.SUPPORTED_OBJTYPES 
    109     motosync.DEBUG_OUTPUT = options.verbose 
    110103 
    111104    prompt_user(options)