2 from __future__ import print_function
10 vimfiles_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
13 hostname = socket.gethostname()
17 # Recursive glob function, from
18 # http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python#2186565
19 def Rglob(path, match):
21 for root, dirnames, filenames in os.walk(path):
22 for filename in fnmatch.filter(filenames, match):
23 matches.append(os.path.join(root, filename))
26 def UpdateReleaseVersion():
27 release_file = os.path.join(vimfiles_dir,'plugin/TagHighlight/data/release.txt')
28 fh = open(release_file,'r')
29 lines = [i for i in fh]
32 fh = open(release_file, 'wb')
34 if line.startswith('release:'):
35 parts = line.strip().split(':')
36 numbers = [int(i) for i in parts[1].split('.')]
37 release = '{0}.{1}.{2}'.format(numbers[0],numbers[1],numbers[2]+1)
38 fh.write('release:'+release+'\n')
40 fh.write(line.strip() + '\n')
44 version_info_initial = ['log','-1','--template=release_revid:{node}\nrelease_date:{date|isodate}']
45 clean_info = ['status']
47 def GenerateVersionInfo():
48 version_file = os.path.join(vimfiles_dir,'plugin/TagHighlight/data/version_info.txt')
50 args = HG + clean_info
51 p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
52 (stdout,stderr) = p.communicate()
54 sys.exit(p.returncode)
57 if len(status_lines) > 0:
59 clean_line = "release_clean:0"
62 clean_line = "release_clean:1"
64 args = HG + version_info_initial
65 p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
66 (stdout,stderr) = p.communicate()
68 # Write as binary for consistent line endings
69 fh = open(version_file, 'wb')
70 fh.write(clean_line + "\n")
72 for line in stdout.split('\n'):
73 if line.startswith('release_'):
77 return version_file, clean
79 def MakeMainRelease(r):
80 # List of paths to include (either explicit files or paths to search)
82 '.py': ['plugin/TagHighlight',__file__],
83 '.vim': ['plugin/TagHighlight.vim','autoload/TagHighlight'],
84 '.txt': ['plugin/TagHighlight/data','plugin/TagHighlight/instructions.txt', 'doc/TagHighlight.txt'],
85 '.spec': ['plugin/TagHighlight/TagHighlight.spec'],
87 filename = 'taghighlight_r{0}.zip'.format(r)
88 MakeZipFile(filename, paths)
90 def MakeZipFile(filename, paths):
92 zipf = zipfile.ZipFile(os.path.join(vimfiles_dir, 'dist', filename), 'w')
94 # Collect the specified paths into a zip file
95 for ext, pathlist in paths.items():
97 # Get the full path (specified relative to vimfiles directory)
98 full_path = os.path.join(vimfiles_dir, path)
99 if os.path.exists(full_path):
100 if os.path.isfile(full_path):
102 elif os.path.isdir(full_path):
103 files = Rglob(full_path, '*' + ext)
105 print("Unrecognised path: " + full_path)
109 dirname = os.path.dirname(os.path.relpath(f,vimfiles_dir))
110 zipf.write(f,os.path.join(dirname, os.path.basename(f)), zipfile.ZIP_DEFLATED)
112 print("No files found for path: " + full_path)
114 print("Path does not exist: " + full_path)
118 def MakeLibraryPackage(r):
120 '.txt': ['plugin/TagHighlight/standard_libraries'],
121 '.taghl': ['plugin/TagHighlight/standard_libraries'],
123 filename = 'taghighlight_standard_libraries_r{0}.zip'.format(r)
124 MakeZipFile(filename, paths)
126 def MakeCompiled(pyexe, pyinstaller_path, zipfilename, platform_dir):
127 initial_dir = os.getcwd()
128 os.chdir(os.path.join(vimfiles_dir, 'plugin/TagHighlight'))
129 args = pyexe + [os.path.join(pyinstaller_path, 'Build.py'), '-y', 'TagHighlight.spec']
130 p = subprocess.Popen(args)#, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
131 (stdout,stderr) = p.communicate()
133 sys.exit(p.returncode)
134 zipf = zipfile.ZipFile(os.path.join(vimfiles_dir,'dist',zipfilename), 'w')
135 for f in Rglob(os.path.join(vimfiles_dir,'plugin/TagHighlight/Compiled/'+platform_dir),'*'):
136 dirname = os.path.dirname(os.path.relpath(f,vimfiles_dir))
137 zipf.write(f,os.path.join(dirname, os.path.basename(f)), zipfile.ZIP_DEFLATED)
139 os.chdir(initial_dir)
141 def MakeWin32Compiled(r):
142 if 'WINPYTHON' in os.environ:
143 # Doesn't work with spaces in the path
144 # (doing the split to allow for running python
146 pyexe = os.environ['WINPYTHON'].split(' ')
148 pyexe = ['python.exe']
149 pyinstaller_path = os.environ['WINPYINSTALLERDIR']
150 MakeCompiled(pyexe, pyinstaller_path, 'taghighlight_r{0}_win32.zip'.format(r), 'Win32')
152 def MakeLinuxCompiled(r):
153 if 'PYTHON' in os.environ:
154 # Doesn't work with spaces in the path
155 # (doing the split to allow for running python
157 pyexe = os.environ['PYTHON']
160 pyinstaller_path = os.environ['PYINSTALLERDIR']
161 MakeCompiled(pyexe, pyinstaller_path, 'taghighlight_r{0}_linux.zip'.format(r), 'Linux')
163 def CheckInChanges(r):
164 args = HG+['commit','-m','Release build {0}'.format(r)]
165 p = subprocess.Popen(args)
166 (stdout,stderr) = p.communicate()
168 sys.exit(p.returncode)
169 args = HG+['tag','taghighlight-release-{0}'.format(r)]
170 p = subprocess.Popen(args)
171 (stdout,stderr) = p.communicate()
173 sys.exit(p.returncode)
175 p = subprocess.Popen(args)
176 (stdout,stderr) = p.communicate()
178 sys.exit(p.returncode)
180 def PublishReleaseVersion():
182 # This function will be used to push generated files to a remote location
183 # to make them available on the web
187 version_file, clean = GenerateVersionInfo()
190 new_release = UpdateReleaseVersion()
191 MakeMainRelease(new_release)
192 os.remove(version_file)
193 MakeWin32Compiled(new_release)
194 MakeLinuxCompiled(new_release)
195 MakeLibraryPackage(new_release)
196 CheckInChanges(new_release)
197 PublishReleaseVersion()
199 print("Distribution not clean: check into Mercurial before making release.")
200 os.remove(version_file)
203 if __name__ == "__main__":