Skip to content

Commit

Permalink
Refactor deploy.py
Browse files Browse the repository at this point in the history
To separate bumping the version number and creating a package.
  • Loading branch information
scurest committed Oct 24, 2018
1 parent 6edfbfb commit ca151dc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
41 changes: 20 additions & 21 deletions deploy.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import argparse
import os
import sys
import re
import subprocess
import shutil

parser = argparse.ArgumentParser()
parser.add_argument("version")

args = parser.parse_args()
pathname = os.path.dirname(sys.argv[0])
import make_package


def replace_in_file(file, expr, new_substr):
Expand All @@ -24,25 +18,30 @@ def replace_in_file(file, expr, new_substr):
outfile.write(line)


this_dir = os.path.dirname(os.path.abspath(__file__))

parser = argparse.ArgumentParser()
parser.add_argument('version')
args = parser.parse_args()

version = args.version.split('.')
version_string = ".".join(version)
version_string = '.'.join(version)
version_tuple = '(%s)' % ', '.join(version)

main_file = os.path.join(pathname, 'addons', 'io_scene_gltf', '__init__.py')
readme_file = os.path.join(pathname, 'README.md')
main_file = os.path.join(this_dir, 'addons', 'io_scene_gltf', '__init__.py')
readme_file = os.path.join(this_dir, 'README.md')

replace_in_file(main_file,
'\'version\': \([0-9\, ]*\)',
'\'version\': (%s)' % ', '.join(version))
r"'version': \([0-9\, ]+\)",
"'version': {}".format(version_tuple))

replace_in_file(readme_file,
'download/[0-9\.]*/io_scene_gltf-[0-9\.]*zip',
'download/{}/io_scene_gltf-{}.zip'.format(version_string, version_string))
r'download/v[0-9\.]+/io_scene_gltf-[0-9\.]+.zip',
'download/v{}/io_scene_gltf-{}.zip'.format(version_string, version_string))

subprocess.call(["git", "add", main_file, readme_file])
subprocess.call(["git", "commit", "-m", "Bumb version number to {}".format(version_string)])
subprocess.call(["git", "tag", "v{}".format(version_string)])
os.chdir(this_dir)
subprocess.call(['git', 'add', main_file, readme_file])
subprocess.call(['git', 'commit', '-m', 'Bump version number to {}'.format(version_string)])
subprocess.call(['git', 'tag', 'v{}'.format(version_string)])

if not os.path.exists('dist'):
os.makedirs('dist')
shutil.make_archive('dist/io_scene_gltf-{}'.format(version_string), 'zip',
'addons')
make_package.make_package(suffix=version_string)
30 changes: 30 additions & 0 deletions make_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import shutil
import tempfile


def make_package(suffix=None):
this_dir = os.path.dirname(os.path.abspath(__file__))
dist_dir = os.path.join(this_dir, 'dist')

if not os.path.exists(dist_dir):
os.makedirs(dist_dir)

with tempfile.TemporaryDirectory() as tmpdir:
shutil.copytree(
os.path.join(this_dir, 'addons', 'io_scene_gltf'),
os.path.join(tmpdir, 'io_scene_gltf'),
ignore=shutil.ignore_patterns('__pycache__'))

zip_name = 'io_scene_gltf'
if suffix:
zip_name += '-' + suffix

shutil.make_archive(
os.path.join('dist', zip_name),
'zip',
tmpdir)


if __name__ == '__main__':
make_package()

0 comments on commit ca151dc

Please sign in to comment.