r76855 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76854‎ | r76855 | r76856 >
Date:23:43, 16 November 2010
Author:diederik
Status:deferred
Tags:
Comment:
Major refactoring of settings / configuration. Updated all property references.
Modified paths:
  • /trunk/tools/editor_trends/config.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/config.py
@@ -22,56 +22,36 @@
2323 import ConfigParser
2424
2525
26 -import settings
 26+import configuration
 27+settings = configuration.Settings()
2728 from utils import utils
28 -try:
29 - from _winreg import *
30 -except ImportError:
31 - pass
3229
33 -def detect_windows_program(program):
34 -
35 - entry = settings.WINDOWS_REGISTER[program]
36 - try:
37 - key = OpenKey(HKEY_CURRENT_USER, entry, 0, KEY_READ)
38 - return QueryValueEx(key, 'Path')[0]
39 - except WindowsError:
40 - return None
4130
4231
43 -def detect_installed_program(program):
44 - platform = settings.OS
45 - if platform == 'Windows':
46 - path = detect_windows_program(program)
47 - return path
48 - else:
49 - raise NotImplementedError
50 -
51 -
5232 def load_configuration(args):
5333 config = ConfigParser.RawConfigParser()
54 - if not utils.check_file_exists(settings.WORKING_DIRECTORY, 'wiki.cfg'):
 34+ if not utils.check_file_exists(settings.working_directory, 'wiki.cfg'):
5535 working_directory = raw_input('Please indicate where you installed Editor Trends Analytics.\nCurrent location is %s\nPress Enter to accept default.' % os.getcwd())
5636 if working_directory == '':
5737 working_directory = os.getcwd()
5838
59 - xml_file_location = raw_input('Please indicate where to store the Wikipedia dump files.\nDefault is: %s\nPress Enter to accept default.' % settings.XML_FILE_LOCATION)
60 - if xml_file_location == '':
61 - xml_file_location = settings.XML_FILE_LOCATION
 39+ settings.input_location = raw_input('Please indicate where to store the Wikipedia dump files.\nDefault is: %s\nPress Enter to accept default.' % settings.input_location)
 40+ if settings.input_location == '':
 41+ settings.input_location = settings.input_location
6242
63 - create_configuration(WORKING_DIRECTORY=working_directory, XML_FILE_LOCATION=xml_file_location)
 43+ create_configuration(working_directory=working_directory, input_location=settings.input_location)
6444
6545 config.read('wiki.cfg')
66 - settings.WORKING_DIRECTORY = config.get('file_locations', 'WORKING_DIRECTORY')
67 - settings.XML_FILE_LOCATION = config.get('file_locations', 'XML_FILE_LOCATION')
 46+ settings.working_directory = config.get('file_locations', 'working_directory')
 47+ settings.input_location = config.get('file_locations', 'xml_file_location')
6848
6949
7050 def create_configuration(**kwargs):
71 - working_directory = kwargs.get('WORKING_DIRECTORY', settings.WORKING_DIRECTORY)
 51+ working_directory = kwargs.get('working_directory', settings.working_directory)
7252 config = ConfigParser.RawConfigParser()
7353 config.add_section('file_locations')
74 - config.set('file_locations', 'WORKING_DIRECTORY', working_directory)
75 - config.set('file_locations', 'XML_FILE_LOCATION', kwargs.get('XML_FILE_LOCATION', settings.XML_FILE_LOCATION))
 54+ config.set('file_locations', 'working_directory', working_directory)
 55+ config.set('file_locations', 'settings.input_location', kwargs.get('settings.input_location', settings.input_location))
7656
7757 fh = utils.create_binary_filehandle(working_directory, 'wiki.cfg', 'wb')
7858 config.write(fh)

Status & tagging log