First time here? Check out the FAQ!

Revision history  [back]

Self customized preferences strip script failed to work for Wing Pro 7.2.5.1.

Hi,

Each time when I am quitting wing, I want to let it strip the following sections from the ~/.wingpro7/preferences:

main.update-history
main.last-prefs-page
main.prefs-version

For this purpose, I create the following script ~/.wingpro7/scripts/preferences-strip.py with the following content:

import wingapi

def topdir(file):
    return os.path.dirname(os.path.abspath(os.path.expanduser(file)))

def _quitting():
  # Do something here
  import os
  import re

  flag = False
  scripts_directory=topdir(__file__)
  settings_directory=os.path.dirname(scripts_directory)
  preferences = settings_directory + '/preferences'
  lines = []
  with open(preferences, 'r') as f:
      for line in f:
          line = line.strip('\n')
          if re.match(r'^main[.](update-history|last-prefs-page|prefs-version)', line):
              flag = True
          else:
              if flag and not re.match(r'[ ]', line):
                  flag = False
          if not flag:
              lines.append(line)

  with open(preferences, 'w') as f:
      f.write('\n'.join(str(item) for item in lines))
      f.write('\n')

wingapi.gApplication.fSingletons.fGuiMgr.connect('about-to-quit', _quitting)

But after I quit wing, it seems the script don't strip the corresponding sections from the ~/.wingpro7/preferences, see following for detail:

$ egrep 'main\.(last-prefs-page|prefs-version)' .wingpro7/preferences
main.last-prefs-page = (0,
main.prefs-version = 8

Any hints for this problem?

Regards, HY

Self customized preferences strip script failed to work for Wing Pro 7.2.5.1.

Hi,

Each time when I am quitting wing, I want to let it strip the following sections from the ~/.wingpro7/preferences:

main.update-history
main.last-prefs-page
main.prefs-version

For this purpose, I create the following script ~/.wingpro7/scripts/preferences-strip.py with the following content:

import wingapi

def topdir(file):
    return os.path.dirname(os.path.abspath(os.path.expanduser(file)))

def _quitting():
  # Do something here
  import os
  import re

  flag = False
  scripts_directory=topdir(__file__)
  settings_directory=os.path.dirname(scripts_directory)
  preferences = settings_directory + '/preferences'
  lines = []
  with open(preferences, 'r') as f:
      for line in f:
          line = line.strip('\n')
          if re.match(r'^main[.](update-history|last-prefs-page|prefs-version)', line):
              flag = True
          else:
              if flag and not re.match(r'[ ]', line):
                  flag = False
          if not flag:
              lines.append(line)

  with open(preferences, 'w') as f:
      f.write('\n'.join(str(item) for item in lines))
      f.write('\n')

wingapi.gApplication.fSingletons.fGuiMgr.connect('about-to-quit', _quitting)

But after I quit wing, it seems the script don't strip the corresponding sections from the ~/.wingpro7/preferences, see following for detail:

$ egrep 'main\.(last-prefs-page|prefs-version)' .wingpro7/preferences
main.last-prefs-page = (0,
main.prefs-version = 8

Any hints for this problem?

Regards, HY