Ticket #2006: 0001-no-hardwired-paths.patch

File 0001-no-hardwired-paths.patch, 2.5 KB (added by walter, 14 years ago)

no hardwired file names

  • extensions/deviceicon/touchpad.py

    From 1bf36a3f2118d7b355316bc4b7b5148d2bc4a41e Mon Sep 17 00:00:00 2001
    From: Walter Bender <walter@sugarlabs.org>
    Date: Fri, 30 Jul 2010 15:49:11 -0400
    Subject: [PATCH 1/2] no hardwired paths
    
    ---
     extensions/deviceicon/touchpad.py |   29 ++++++++++++++++++++++-------
     1 files changed, 22 insertions(+), 7 deletions(-)
    
    diff --git a/extensions/deviceicon/touchpad.py b/extensions/deviceicon/touchpad.py
    index 7f3ecb5..897961f 100644
    a b TOUCHPAD_MODES = ['capacitive', 'resistive'] 
    3232STATUS_TEXT = {TOUCHPAD_MODES[0]: _('finger'), TOUCHPAD_MODES[1]: _('stylus')}
    3333STATUS_ICON = {TOUCHPAD_MODES[0]: 'touchpad-' + TOUCHPAD_MODES[0],
    3434               TOUCHPAD_MODES[1]: 'touchpad-' + TOUCHPAD_MODES[1]}
    35 # FLAG_PATH is used to preserve status between boots.
    36 FLAG_PATH = '/home/olpc/.olpc-pentablet-mode'
     35# FLAG_FILE is used to preserve status between boots.
     36FLAG_FILE = '.olpc-pentablet-mode'
    3737# NODE_PATH is used to communicate with the touchpad device.
    3838NODE_PATH = '/sys/devices/platform/i8042/serio1/ptmode'
    3939
    def setup(tray): 
    103103    if os.path.exists(NODE_PATH):
    104104        tray.add_device(DeviceView())
    105105
     106        # if _flag_path exists, set the initial device value to stylus
     107        _flag_path = os.join(os.environ['HOME'], FLAG_FILE)
     108        if os.path.exists(_flag_path):
     109            write_to_node_file(str(TOUCHPAD_MODES.index('stylus')))
     110
    106111
    107112def read_touchpad_mode():
    108113    """ Read the touchpad mode from the node path. """
    def write_touchpad_mode(touchpad): 
    117122    """ Write the touchpad mode to the node path and set/unset the flag. """
    118123    touchpad_mode_index = TOUCHPAD_MODES.index(touchpad)
    119124
    120     node_file_handle = open(NODE_PATH, 'w')
    121     node_file_handle.write(str(touchpad_mode_index))
    122     node_file_handle.close()
     125    write_to_node_file(str(touchpad_mode_index))
    123126
     127    _flag_path = os.join(os.environ['HOME'], FLAG_FILE)
    124128    if touchpad_mode_index == 0:
    125         if os.path.exists(FLAG_PATH):
     129        if os.path.exists(_flag_path):
    126130            os.remove(FLAG_PATH)
    127131    else:
    128         flag_file_handle = open(FLAG_PATH, 'w')
     132        flag_file_handle = open(_flag_path, 'w')
    129133        flag_file_handle.close()
     134
     135
     136def write_to_node_file(value):
     137    """ Write to node path, catching exception is there is a problem """
     138    try:
     139        node_file_handle = open(NODE_PATH, 'w')
     140    except IOError, e:
     141        print e
     142        return
     143    node_file_handle.write(value)
     144    node_file_handle.close()