a1b6c1926cf57549b139a991c67c22f443e06389
[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     assert os.path.isfile(src)\r
96 \r
97     # Destination directory must not exist. It must be created first.\r
98     dst_dir = os.path.normpath(os.path.join(dist_dir, 'bin', subdir))\r
99     assert not os.path.isdir(dst_dir)\r
100     os.makedirs(dst_dir)\r
101 \r
102     # Copy the file.\r
103     print("Copying '{}'".format(src))\r
104     shutil.copy2(src, dst_dir)\r
105 \r
106 \r
107 def getBinariesZipBareName():\r
108     ver = getDoxygenVersion()\r
109     sha, dstamp, tstamp = gitSHA_date_time()\r
110     fname = 'doxygenw{}_{}.zip'.format(dstamp, ver.replace('.', '_'))\r
111     return fname\r
112 \r
113 \r
114 def getTranslatorReportZipBareName():\r
115     ver = getDoxygenVersion()\r
116     sha, dstamp, tstamp = gitSHA_date_time()\r
117     fname = 'tr{}_{}.zip'.format(dstamp, ver.replace('.', '_'))\r
118     return fname\r
119 \r
120 \r
121 def zipBinaries(distr_dir):\r
122     # Build the zip filename. It is to be located at the same level as distr_dir.\r
123     zip_bare_name = getBinariesZipBareName()\r
124     dst, distr_subdir = os.path.split(distr_dir)\r
125     zip_full_name = os.path.join(dst, zip_bare_name)\r
126 \r
127     if os.path.isfile(zip_full_name):\r
128         print("Removing the existing '{}'".format(zip_full_name))\r
129         os.remove(zip_full_name)\r
130 \r
131     # Change the working directory to destination directory and zip from\r
132     # there using the bare names so that the full path is not zipped inside.\r
133     wd = os.getcwd()\r
134     os.chdir(dst)\r
135     print("Zipping new '{}'".format(zip_full_name))\r
136     subprocess.call('zip -r {} {}'.format(zip_bare_name, distr_subdir), shell=True)\r
137     os.chdir(wd)  # back to the original working directory\r
138 \r
139 \r
140 def buildAndZipTranslatorReport(distr_dir):\r
141     # Build the translator report zip filename. It is to be located at the same\r
142     # level as distr_dir.\r
143     zip_bare_name = getTranslatorReportZipBareName()\r
144     dst, subdir = os.path.split(distr_dir)\r
145     zip_full_name = os.path.join(dst, zip_bare_name)\r
146 \r
147     if os.path.isfile(zip_full_name):\r
148         print("Removing the existing '{}'".format(zip_full_name))\r
149         os.remove(zip_full_name)\r
150     print("Zipping new '{}'".format(zip_full_name))\r
151 \r
152     # Change the working directory to the doc one and generate\r
153     # the translator report.\r
154     sdir, fname = getThisScriptPathAndName()\r
155     docdir = os.path.join(sdir, '..', 'doc')\r
156     assert os.path.isdir(docdir)\r
157     wd = os.getcwd()\r
158     os.chdir(docdir)\r
159     subprocess.call('python translator.py', shell=True)\r
160 \r
161     # Zip the generated translator_report.txt.\r
162     subprocess.call('zip -r {} {}'.format(zip_full_name,\r
163                                           'translator_report.txt'), shell=True)\r
164 \r
165     os.chdir(wd)  # back to the original working directory\r
166 \r
167 \r
168 def mailto():\r
169 \r
170     # Information for the letter.\r
171     ver = getDoxygenVersion()\r
172     sha, dstamp, tstamp = gitSHA_date_time()\r
173     doxzipname = getBinariesZipBareName()\r
174     trzipname = getTranslatorReportZipBareName()\r
175 \r
176     subject = 'Windows binaries available for {}-{} at SourceForge'.format(ver, dstamp)\r
177     subject = subject.replace(' ', '%20')\r
178 \r
179     body = textwrap.dedent('''\\r
180         Hi,\r
181 \r
182         If interested, you can download the doxygen binaries\r
183         compiled for MS Windows from\r
184 \r
185           http://sourceforge.net/projects/doxygen/files/snapshots/doxygen-1.8-svn/windows\r
186 \r
187         This is the place where you should find also the next\r
188         releases.  Name of the archive file is\r
189 \r
190           {}\r
191 \r
192         The related translator report can be found inside the directory\r
193 \r
194           http://sourceforge.net/projects/doxygen/files/snapshots/doxygen-1.8-svn/translator_reports/\r
195 \r
196         Name of the archive file is\r
197 \r
198           {}\r
199 \r
200         The binaries are NOT created automatically, so it may\r
201         happen that some newer sources were not compiled\r
202         because I am not present to do that or I forgot... ;)\r
203 \r
204         Regards,\r
205             Petr\r
206 \r
207         --\r
208         Petr Prikryl (prikryl at atlas dot cz)''').format(doxzipname, trzipname)\r
209     body = body.replace('\n', '%0d')\r
210 \r
211     # Make the mailto URI and launch the mailer.\r
212     to_addr = 'doxygen-users@lists.sourceforge.net'\r
213     mailtoURI = 'mailto:%s?subject=%s&body=%s' % (to_addr, subject, body)\r
214     os.startfile(mailtoURI)\r
215 \r
216 \r
217 if __name__ == '__main__':\r
218     # Create the empty directory for the distribution files.\r
219     dist_dir = getEmptyDistribDir()\r
220 \r
221     # Copy the compiled binaries to the distribution directory and zip them.\r
222     copyBinaries(dist_dir, 'Debug')\r
223     copyBinaries(dist_dir, 'Debug64')\r
224     copyBinaries(dist_dir, 'Release')\r
225     copyBinaries(dist_dir, 'Release64')\r
226     zipBinaries(dist_dir)\r
227 \r
228     # The translator report...\r
229     buildAndZipTranslatorReport(dist_dir)\r
230 \r
231     # Launch the mailer with the generated message body.\r
232     mailto()