Imported Upstream version 1.8.8
[platform/upstream/doxygen.git] / winbuild / pack_the_distribution_for_windows.py
1 #!python2\r
2 \r
3 from __future__ import print_function\r
4 \r
5 import os\r
6 import re\r
7 import shutil\r
8 import subprocess\r
9 import sys\r
10 import textwrap\r
11 \r
12 \r
13 def gitSHA_date_time():\r
14     cmd = 'git rev-parse --short HEAD'\r
15     p = subprocess.Popen(cmd, stdout=subprocess.PIPE)\r
16     output = p.communicate()[0]\r
17     output = output.decode('ASCII')\r
18     p.wait()\r
19     sha = output.strip()\r
20 \r
21     cmd = 'git show -s --format="%ci" ' + sha\r
22     p = subprocess.Popen(cmd, stdout=subprocess.PIPE)\r
23     output = p.communicate()[0]\r
24     output = output.decode('ASCII')\r
25     p.wait()\r
26     date = output.strip()\r
27     lst = date.split()               # string like '2013-06-21 09:23:47 +0200'\r
28     dstamp = lst[0].replace('-', '') # '20130621' for the date\r
29     tstamp = lst[1].replace(':', '') # '092347' for the time\r
30 \r
31     return sha, dstamp, tstamp\r
32 \r
33 \r
34 def getDoxygenVersion():\r
35     # ... from the VERSION file.\r
36     sdir, fname = getThisScriptPathAndName()\r
37     version_fname = os.path.join(sdir, '..', 'VERSION')\r
38 \r
39     with open(version_fname) as f:\r
40         lst = f.readlines()\r
41 \r
42     doxver = lst[0].strip()\r
43 \r
44     m = re.match(r'^(?P<ver>[0-9.]+)(-(?P<date>\d{8}))?', doxver)\r
45     assert m\r
46     ver = m.group('ver')\r
47     return ver\r
48 \r
49 \r
50 def getThisScriptPathAndName():\r
51     script_fname = os.path.realpath(__file__)\r
52     sdir, fname = os.path.split(script_fname)\r
53     return sdir, fname\r
54 \r
55 \r
56 def getEmptyDistribDir():\r
57     # Get this script full path, name, and the script subdir name\r
58     # (for checking the location).\r
59     sdir, fname = getThisScriptPathAndName()\r
60     subdir = os.path.basename(sdir)\r
61     assert subdir == 'winbuild'\r
62 \r
63     # The distribution directory will be a subdirectory of the "../__put"\r
64     # (created if it does not exist, not the part of the git repo).\r
65     target_dir = os.path.normpath(os.path.join(sdir, '..', '__put'))\r
66     if not os.path.exists(target_dir):\r
67         os.mkdir(target_dir)\r
68     assert os.path.isdir(target_dir)\r
69 \r
70     # The distribution subdir is composed out of 'Doxygen-', version stamp,\r
71     # timestamp, and commit id (partial SHA). Ignore the date from the VERSION\r
72     # file, take the commit date.\r
73     ver = getDoxygenVersion()\r
74     sha, dstamp, tstamp = gitSHA_date_time()\r
75     dist_subdir = 'Doxygen-' + ver + '-' + dstamp + tstamp\r
76     dist_dir = os.path.join(target_dir, dist_subdir)\r
77     print(dist_dir)\r
78     if os.path.isdir(dist_dir):\r
79         print("Removing the existing '{}'".format(dist_dir))\r
80         shutil.rmtree(dist_dir)\r
81     assert not os.path.exists(dist_dir)\r
82     print("Creating the new '{}'".format(dist_dir))\r
83     os.mkdir(dist_dir)\r
84     assert os.path.isdir(dist_dir)\r
85 \r
86     return dist_dir\r
87 \r
88 \r
89 def copyBinaries(dist_dir, subdir):\r
90     '''Copy the Windows binaries (doxygen.exe only) to the dist_dir directory.'''\r
91 \r
92     # Source file should exist.\r
93     sdir, fname = getThisScriptPathAndName()\r
94     src = os.path.normpath(os.path.join(sdir, '..', 'bin', subdir, 'doxygen.exe'))\r
95     if os.path.isfile(src):\r
96         # Destination directory must not exist. It must be created first.\r
97         dst_dir = os.path.normpath(os.path.join(dist_dir, 'bin', subdir))\r
98         assert not os.path.isdir(dst_dir)\r
99         os.makedirs(dst_dir)\r
100 \r
101         # Copy the file.\r
102         print("Copying '{}'".format(src))\r
103         shutil.copy2(src, dst_dir)\r
104     else:\r
105         print("The binary '" + src + "'")\r
106         print('was not found. It will not be present in the distribution.')\r
107 \r
108 \r
109 def getBinariesZipBareName():\r
110     ver = getDoxygenVersion()\r
111     sha, dstamp, tstamp = gitSHA_date_time()\r
112     fname = 'doxygenw{}_{}.zip'.format(dstamp, ver.replace('.', '_'))\r
113     return fname\r
114 \r
115 \r
116 def getTranslatorReportZipBareName():\r
117     ver = getDoxygenVersion()\r
118     sha, dstamp, tstamp = gitSHA_date_time()\r
119     fname = 'tr{}_{}.zip'.format(dstamp, ver.replace('.', '_'))\r
120     return fname\r
121 \r
122 \r
123 def zipBinaries(distr_dir):\r
124     # Build the zip filename. It is to be located at the same level as distr_dir.\r
125     zip_bare_name = getBinariesZipBareName()\r
126     dst, distr_subdir = os.path.split(distr_dir)\r
127     zip_full_name = os.path.join(dst, zip_bare_name)\r
128 \r
129     if os.path.isfile(zip_full_name):\r
130         print("Removing the existing '{}'".format(zip_full_name))\r
131         os.remove(zip_full_name)\r
132 \r
133     # Change the working directory to destination directory and zip from\r
134     # there using the bare names so that the full path is not zipped inside.\r
135     wd = os.getcwd()\r
136     os.chdir(dst)\r
137     print("Zipping new '{}'".format(zip_full_name))\r
138     subprocess.call('zip -r {} {}'.format(zip_bare_name, distr_subdir), shell=True)\r
139     os.chdir(wd)  # back to the original working directory\r
140 \r
141 \r
142 def buildAndZipTranslatorReport(distr_dir):\r
143     # Build the translator report zip filename. It is to be located at the same\r
144     # level as distr_dir.\r
145     zip_bare_name = getTranslatorReportZipBareName()\r
146     dst, subdir = os.path.split(distr_dir)\r
147     zip_full_name = os.path.join(dst, zip_bare_name)\r
148 \r
149     if os.path.isfile(zip_full_name):\r
150         print("Removing the existing '{}'".format(zip_full_name))\r
151         os.remove(zip_full_name)\r
152     print("Zipping new '{}'".format(zip_full_name))\r
153 \r
154     # Change the working directory to the doc one and generate\r
155     # the translator report.\r
156     sdir, fname = getThisScriptPathAndName()\r
157     docdir = os.path.join(sdir, '..', 'doc')\r
158     assert os.path.isdir(docdir)\r
159     wd = os.getcwd()\r
160     os.chdir(docdir)\r
161     subprocess.call('python translator.py', shell=True)\r
162 \r
163     # Zip the generated translator_report.txt.\r
164     subprocess.call('zip -r {} {}'.format(zip_full_name,\r
165                                           'translator_report.txt'), shell=True)\r
166 \r
167     os.chdir(wd)  # back to the original working directory\r
168 \r
169 \r
170 def mailto():\r
171 \r
172     # Information for the letter.\r
173     ver = getDoxygenVersion()\r
174     sha, dstamp, tstamp = gitSHA_date_time()\r
175     doxzipname = getBinariesZipBareName()\r
176     trzipname = getTranslatorReportZipBareName()\r
177 \r
178     subject = 'Windows binaries available for {}-{} at SourceForge'.format(ver, dstamp)\r
179     subject = subject.replace(' ', '%20')\r
180 \r
181     body = textwrap.dedent('''\\r
182         Hi,\r
183 \r
184         If interested, you can download the doxygen binaries\r
185         compiled for MS Windows from\r
186 \r
187           http://sourceforge.net/projects/doxygen/files/snapshots/doxygen-1.8-svn/windows\r
188 \r
189         This is the place where you should find also the next\r
190         releases.  Name of the archive file is\r
191 \r
192           {}\r
193 \r
194         The related translator report can be found inside the directory\r
195 \r
196           http://sourceforge.net/projects/doxygen/files/snapshots/doxygen-1.8-svn/translator_reports/\r
197 \r
198         Name of the archive file is\r
199 \r
200           {}\r
201 \r
202         The binaries are NOT created automatically, so it may\r
203         happen that some newer sources were not compiled\r
204         because I am not present to do that or I forgot... ;)\r
205 \r
206         Regards,\r
207             Petr\r
208 \r
209         --\r
210         Petr Prikryl (prikryl at atlas dot cz)''').format(doxzipname, trzipname)\r
211     body = body.replace('\n', '%0d')\r
212 \r
213     # Make the mailto URI and launch the mailer.\r
214     to_addr = 'doxygen-users@lists.sourceforge.net'\r
215     mailtoURI = 'mailto:%s?subject=%s&body=%s' % (to_addr, subject, body)\r
216     os.startfile(mailtoURI)\r
217 \r
218 \r
219 if __name__ == '__main__':\r
220     # Create the empty directory for the distribution files.\r
221     dist_dir = getEmptyDistribDir()\r
222 \r
223     # Copy the compiled binaries to the distribution directory and zip them.\r
224     copyBinaries(dist_dir, 'Debug')\r
225     copyBinaries(dist_dir, 'Debug64')\r
226     copyBinaries(dist_dir, 'Release')\r
227     copyBinaries(dist_dir, 'Release64')\r
228     zipBinaries(dist_dir)\r
229 \r
230     # The translator report...\r
231     buildAndZipTranslatorReport(dist_dir)\r
232 \r
233     # Launch the mailer with the generated message body.\r
234     mailto()