OSDN Git Service

b1cdc94019f95450d45c1a14a09c8c3465b1d0e2
[winmerge-jp/winmerge-jp.git] / Tools / Scripts / UpgradeProjects.py
1 #############################################################################
2 ##    License (GPLv2+):
3 ##    This program is free software; you can redistribute it and/or modify
4 ##    it under the terms of the GNU General Public License as published by
5 ##    the Free Software Foundation; either version 2 of the License, or
6 ##    (at your option) any later version.
7 ##
8 ##    This program is distributed in the hope that it will be useful, but
9 ##    WITHOUT ANY WARRANTY; without even the implied warranty of
10 ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ##    General Public License for more details.
12 ##
13 ##    You should have received a copy of the GNU General Public License
14 ##    along with this program; if not, write to the Free Software
15 ##    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 #############################################################################
17
18 # Copyright (c) 2008-2009 Kimmo Varis <kimmov@winmerge.org>
19
20 # $Id$
21
22 # A script for upgrading VS solution- and project-files from VS2003 to newer
23 # VS versions. This script calls VS binary to upgrade every file listed. If the
24 # file is solution file, then all projects in the solution are also upgraded.
25 #
26 # For more info about using VS command line, see:
27 # http://www.devsource.com/c/a/Using-VS/Working-at-the-Visual-Studio-Command-Line/1/
28
29 import getopt
30 import os
31 import subprocess
32 import sys
33
34 # The version of the script
35 script_version = 0.2
36
37 solutions = [r'Externals\expat\expat.sln',
38     r'Externals\pcre\Win32\PCRE.sln',
39     r'WinMerge.sln']
40
41 projects = [r'Externals\scew\win32\scew.vcproj',
42     r'ShellExtension\ShellExtension.vcproj']
43
44 # TODO: read this from Tools.ini
45 vs_path = r'C:\Program Files\Microsoft Visual Studio 9.0'
46
47 def upgrade_projects(root_path):
48     vs_binary = os.path.join(vs_path, 'Common7/IDE')
49     vs_binary = os.path.join(vs_binary, 'devenv.com')
50     
51     for solution in solutions:
52         sol_file = os.path.join(root_path, solution)
53         print 'Upgrading VS solution file: ' + sol_file
54         subprocess.call([vs_binary, sol_file, '/Upgrade'], shell = True)
55
56     for project in projects:
57         proj_file = os.path.join(root_path, project)
58         print 'Upgrading project file: ' + proj_file
59         subprocess.call([vs_binary, proj_file, '/Upgrade'], shell = True)
60
61 def usage():
62     '''Print script usage information.'''
63
64     print 'UpgradeProjects.py - version ' + str(script_version)
65     print 'Script to upgrade VS solution/project files.'
66     print 'Usage: UpgradeProjects.py [-h] [path]'
67     print 'Where:'
68     print '  -h, --help Print this help.'
69     print '  path Root path for WinMerge.'
70     print 'For example: UpgradeProjects.py ../..'
71     print '  which upgrades current project when run from Scripts folder.'
72
73 def main(argv):
74     root_path = ''
75     if len(argv) > 0:
76         opts, args = getopt.getopt(argv, 'h', ['help'])
77
78         for opt, arg in opts:
79             if opt in ('-h', '--help'):
80                 usage()
81                 sys.exit()
82          
83         if len(args) == 1:
84             rel_path = args[0]
85             root_path = os.path.abspath(rel_path)
86
87     # If not root path given, use current folder as root path
88     if root_path == '':
89         root_path = os.getcwd()
90
91     if not os.path.exists(root_path):
92         print 'ERROR: Cannot find path: ' + root_path
93         sys.exit()
94     
95     print 'Upgrading VS solution- and project-file in folder: ' + root_path
96     upgrade_projects(root_path)
97
98 # MAIN #
99 if __name__ == "__main__":
100     main(sys.argv[1:])
101