Index: trunk/tools/editor_trends/config.py |
— | — | @@ -22,56 +22,36 @@ |
23 | 23 | import ConfigParser |
24 | 24 | |
25 | 25 | |
26 | | -import settings |
| 26 | +import configuration |
| 27 | +settings = configuration.Settings() |
27 | 28 | from utils import utils |
28 | | -try: |
29 | | - from _winreg import * |
30 | | -except ImportError: |
31 | | - pass |
32 | 29 | |
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 |
41 | 30 | |
42 | 31 | |
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 | | - |
52 | 32 | def load_configuration(args): |
53 | 33 | 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'): |
55 | 35 | working_directory = raw_input('Please indicate where you installed Editor Trends Analytics.\nCurrent location is %s\nPress Enter to accept default.' % os.getcwd()) |
56 | 36 | if working_directory == '': |
57 | 37 | working_directory = os.getcwd() |
58 | 38 | |
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 |
62 | 42 | |
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) |
64 | 44 | |
65 | 45 | 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') |
68 | 48 | |
69 | 49 | |
70 | 50 | def create_configuration(**kwargs): |
71 | | - working_directory = kwargs.get('WORKING_DIRECTORY', settings.WORKING_DIRECTORY) |
| 51 | + working_directory = kwargs.get('working_directory', settings.working_directory) |
72 | 52 | config = ConfigParser.RawConfigParser() |
73 | 53 | 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)) |
76 | 56 | |
77 | 57 | fh = utils.create_binary_filehandle(working_directory, 'wiki.cfg', 'wb') |
78 | 58 | config.write(fh) |