4 # This file is part of bertos.
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.
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.
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
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.
29 # Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
41 from optparse import OptionParser
43 def createBertosPreset(source, destination):
44 os.makedirs(destination)
45 project_file = os.path.join(source, "project.bertos")
46 shutil.copy(project_file, destination)
47 project_info = pickle.loads(open(project_file, "r").read())
49 user_project_dir = os.path.join(source, project_info["PROJECT_NAME"])
51 user_project_dir = os.path.join(source, os.path.basename(source))
52 if not os.path.exists(user_project_dir):
53 print "Project in %s is not well formed" %source
54 hw_dir = os.path.join(user_project_dir, "hw")
55 new_hw_dir = os.path.join(destination, "hw")
56 shutil.copytree(hw_dir, new_hw_dir)
57 cfg_dir = os.path.join(user_project_dir, "cfg")
58 new_cfg_dir = os.path.join(destination, "cfg")
59 shutil.copytree(cfg_dir, new_cfg_dir)
60 main_file = os.path.join(user_project_dir, "main.c")
61 new_main_file = os.path.join(destination, "main.c")
62 shutil.copy(main_file, new_main_file)
63 print "Preset correctly created: REMEMBER TO WRITE THE description FILE INTO THE PRESET DIRECTORY"
68 print 'Invalid usage:\nuse: ./preset_from_project.py PROJECT_DIRECTORY DESTINATION_DIRECTORY'
70 if not os.path.exists(args[1]):
71 print 'The given project directory (%s) doesn\'t exists' %args[1]
73 if not os.path.exists(os.path.join(args[1], 'project.bertos')):
74 print 'No project.bertos file found in %s' %args[1]
76 if os.path.exists(args[2]):
77 print "Destination directory (%s) already exists" %args[2]
78 createBertosPreset(args[1], args[2])
80 if __name__ == '__main__':