Remove previous hack to let the new infrastructure work.
[bertos.git] / wizard / bertos.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction.  Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License.  This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 # $Id$
32 #
33 # Author: Lorenzo Berni <duplo@develer.com>
34 #
35
36 import os
37 import sys
38 from distutils.dep_util import newer
39
40 from PyQt4.QtCore import *
41 from PyQt4.QtGui import *
42
43 import exception_handler
44
45 from BProject import BProject
46
47 from BWizard import BWizard
48
49 from BIntroPage import BIntroPage
50 from BFolderPage import BFolderPage
51 from BBoardPage import BBoardPage
52 from BProjectPresets import BProjectPresets
53 from BOpenPage import BOpenPage
54 from BVersionPage import BVersionPage
55 from BCpuPage import BCpuPage
56 from BToolchainPage import BToolchainPage
57 from BModulePage import BModulePage
58 from BCreationPage import BCreationPage
59 from BFinalPage import BFinalPage
60
61 from BEditingDialog import BEditingDialog, BVersionDialog, BToolchainDialog
62
63 from const import DATA_DIR
64
65 from LoadException import VersionException, ToolchainException
66
67 def newProject():
68     QApplication.instance().project = BProject()
69     page_list = [BIntroPage, BFolderPage, BVersionPage, BBoardPage, BProjectPresets, BCpuPage, BToolchainPage, BModulePage, BCreationPage, BFinalPage]
70     wizard = BWizard(page_list)
71     wizard.show()
72     wizard.exec_()
73     project = QApplication.instance().project
74     to_be_opened = project.info("TO_BE_OPENED")
75     command_lines = project.info("COMMAND_LINES")
76     relevant_files = project.info("RELEVANT_FILES")
77     if to_be_opened:
78         for ide in to_be_opened:
79             command_line = command_lines[ide]
80             relevant_file = relevant_files[ide]
81             QProcess.startDetached(command_line, [relevant_file,])
82     sys.exit()
83
84 def editProject(project_file):
85     info_dict = {}
86     while(True):
87         # Empty project is the default fallback.
88         QApplication.instance().project = BProject()
89         try:
90             QApplication.instance().project = BProject(project_file, info_dict)
91         except VersionException:
92             QMessageBox.critical(
93                 None,
94                 QObject().tr("BeRTOS version not found!"),
95                 QObject().tr("The selected BeRTOS version was not found, please select another one...")
96             )
97             dialog = BVersionDialog()
98             if dialog.exec_():
99                 version = dialog.version_page.currentVersion()
100                 info_dict["BERTOS_PATH"] = version
101             continue
102         except ToolchainException, exc:
103             QMessageBox.critical(
104                 None,
105                 QObject().tr("Toolchain not found!"),
106                 QObject().tr("The selected toolchain was not found, please select another one...")
107             )
108             QApplication.instance().project = exc.partial_project
109             dialog = BToolchainDialog()
110             if dialog.exec_():
111                 toolchain = dialog.toolchain_page.currentToolchain()
112                 info_dict["TOOLCHAIN"] = toolchain
113             continue
114         break
115     dialog = BEditingDialog()
116     dialog.exec_()
117
118 def main():
119     app = QApplication(sys.argv)
120     app.settings = QSettings("Develer", "Bertos Configurator")
121     # Development utility lines, to be removed for production
122     datadir = DATA_DIR
123     qrc, rcc = os.path.join(datadir, 'bertos.qrc'), os.path.join(datadir, 'bertos.rcc')
124     if not (hasattr(sys, "frozen") and sys.frozen) and newer(qrc, rcc):
125         os.system("rcc -binary %s -o %s" %(qrc, rcc))
126     QResource.registerResource(rcc)
127     if len(sys.argv) == 3 and sys.argv[1] == "--edit":
128         editProject(os.path.abspath(sys.argv[2]))
129     else:
130         newProject()
131
132
133 if __name__ == '__main__':
134     main()
135