Skip to content

Commit

Permalink
Added distributable-zipping script
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeiren committed Aug 31, 2017
1 parent 899f8b3 commit 5813862
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions utility/zip_release_distributables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This python script is intended for zipping release-ready distributable files for EasyImgur

#!/usr/bin/env python
import os
import zipfile
import struct
import re


def tryParseVersionFromString(string):
result = re.match("(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)", string)
if result is None:
return None
major = int(result.group("major"))
minor = int(result.group("minor"))
patch = int(result.group("patch"))
return (major, minor, patch)


# Asks the user (with additional confirmation request) about the version of this executable and returns a tuple with (major, minor, patch) version numbers
def inputDistVersion():
first_attempt = None
second_attempt = None

while True:
first_attempt = tryParseVersionFromString(raw_input("Which version are we dealing with (major.minor.patch)? "))
if first_attempt is not None:
break

while True:
second_attempt = tryParseVersionFromString(raw_input("Confirm the input version (major.minor.patch): "))
if second_attempt is not None:
break

# If both inputs are the same, return the result
if first_attempt == second_attempt:
return first_attempt

return None


# Returns the path to the dist folder
def getDistPath():
return os.path.abspath(__file__ + "../../../dist/release/")


# Zip all files in folder 'path' to zipfile handle 'ziph'. If the zipfile itself is present in the
# target folder, it is ignored
def zipFolder(path, ziph):
print "Zipping to file '{0}'...".format(ziph.filename)

for root, dirs, files in os.walk(path):
for file in files:
# Don't attempt to zip the target zipfile itself if it is present in the target directory.
if file == os.path.basename(ziph.filename):
continue

print " zipping: {0}".format(file)
ziph.write(os.path.join(root, file), file)

print "Zip finished"


def main():
version = inputDistVersion()

if version is None:
print "The input version numbers do not match!"
return

zipfilename = os.path.join(getDistPath(), "EasyImgur_v{}-{}-{}.zip".format(version[0], version[1], version[2]))
zipf = zipfile.ZipFile(zipfilename, 'w', zipfile.ZIP_DEFLATED)
zipFolder(getDistPath(), zipf)
zipf.close()

if __name__ == '__main__':
main()

0 comments on commit 5813862

Please sign in to comment.