File: mergeall-products/unzipped/build/build-source/build.py
#!/usr/bin/env python3
"""
=============================================================================
Make a mergeall source-code package (a zipfile scrubbed of private content).
This is just a few moves and a zip; there are no frozen builds here.
Unlike the app/exe scripts, this may be run on Windows, Mac, or Linux.
Run this script in its own folder; it works on a copy in its folder
(which comes from an initial temp copy to avoid recursion issues).
This is now a nested step in the top-level's _publish.py, which also
generates all thumbspage galleries in the package.
*NOTE*: remove any unzipped app/exe folders in build/ before running this.
*NOTE*: moves prior zip to 'prev-' auto: back this out to save it on reruns.
[3.2] Updated for new macOS build machine, and mergeall-android-scripts
helper-scripts nesting in the source-pkg folder. It's not clear if this
or the Android GUI patch files should be included in Mergeall's src; these
are maintained separately and updated often, and the scripts package adds
an extra 30-40M. As a compromise, the source package here includes just
the 2 GUI patch files and the helper scripts themselves, with pointers
to the full presentations online. ziptools is also embedded in Mergeall
for historical reasons (it began as a test tool here), and is now updated
independently and often too; punt on this - too much work to rip out now...
=============================================================================
"""
import os, sys, shutil
join, sep = os.path.join, os.path.sep
startdir = os.getcwd() # this build script's dir
# 'python3' fails in both IDLE and PyEdit RunCode (env's PATH not inherited?)
python = sys.executable
#----------------------------------------------------------------------------
# make app's icon if one doesn't already exist
#----------------------------------------------------------------------------
pass # handle this manually in build-app-exe, as icons differ per platform
#----------------------------------------------------------------------------
# copy mergell to avoid accidents and recursive-copy loop
#----------------------------------------------------------------------------
# automated setup - run in this file's dir
if sys.platform.startswith('darwin'): # [3.2]
temp = '/Users/me/Desktop/tempsrc' # cp can't include self!
elif sys.platform.startswith('win'):
temp = r'C:\Users\mark\Desktop\tempsrc' # or use $HOME, etc.
elif sys.platform.startswith('linux'):
temp = '/home/name/Desktop/tempsrc'
if os.path.exists(temp):
shutil.rmtree(temp)
os.mkdir(temp)
# copy all to temp (can't just copy to '.' - it's part of the tree copied)
print('Building tree')
shutil.copytree(join('..', '..', '..', 'mergeall'),
join(temp, 'mergeall'), symlinks=True) # with metadata, nofollow links
#----------------------------------------------------------------------------
# make the source zipfile
#----------------------------------------------------------------------------
# zip command: use portable ziptools (vs: 'zip -r %s %s' % (thezip, thedir))
thedir = 'Mergeall-source'
thezip = thedir + '.zip'
if sys.platform.startswith('darwin'):
code = '~/MY-STUFF/Code/ziptools/link'
elif sys.platform.startswith('win'):
code = r'C:\MY-STUFF\Code\mergeall\test\ziptools'
elif sys.platform.startswith('linux'):
code = '/media/name/End_of_the_drive/MARKS-STUFF/Code/mergeall/test/ziptools'
zipit = '%s %s/zip-create.py %s %s -skipcruft' % (python, code, thezip, thedir)
zipit = zipit.replace('/', os.sep)
# rename and move source product folder here (to '.' - this script's own folder)
shutil.move(join(temp, 'mergeall'), join(temp, thedir))
if os.path.exists(thedir):
shutil.rmtree(thedir) # nuke bogus retained temp?
shutil.move(join(temp, thedir), '.') # to this script's folder
shutil.rmtree(temp) # rm temp build tree
# remove zipped app, exe, and src pkgs in the build tree for space
for (root, subs, files) in os.walk(join(thedir, 'build')):
for file in files:
if file.startswith(('Mergeall', 'prev-Mergeall')) and file.endswith('.zip'):
filepath = join(root, file)
print('Removing', filepath)
os.remove(filepath)
dummy = open(filepath + '.stripped', 'w')
dummy.write('**REMOVED**')
dummy.close()
# drop other non-public stuff: _private, etc. (but not {__sloc__, __version__}.py)
for item in os.listdir(thedir):
itempath = join(thedir, item)
if (item[0] == '_' and os.path.isdir(itempath)):
print('Removing', itempath)
shutil.rmtree(itempath)
# move m-a-s scripts (only) to a more general subfolder [3.2]
ascripts = join(thedir, 'android-scripts-and-gui', 'scripts')
for item in os.listdir(ascripts):
if item != '_README.txt':
os.remove(item)
mas = join(thedir, 'mergeall-android-scripts') # in the copy in '.'
for item in os.listdir(mas):
if item.endswith('.sh'):
shutil.copy2(join(mas, item), join(ascripts, item)) # with metadata, no links
shutil.rmtree(mas)
os.remove(join(thedir, 'mergeall-android-scripts.zip--moved.txt'))
# make sure we have the most recent android gui patches [3.2]
atk = join(thedir, 'android-scripts-and-gui', 'gui')
pass # handle this manually; paths differ per platform, and these may be at eol
# nested system cleanup (uncouple this someday!)
shutil.rmtree(join(thedir, 'test', 'ziptools', '__private__'))
# zip the reorganized source folder
if os.path.exists(thezip):
shutil.move(thezip, 'prev-'+thezip) # save previous version
os.system(zipit) # run zip in build-source
shutil.rmtree(thedir) # rm temp folder copy
print('Done: see', thezip)
# +unzip and copy elsewhere for easy access or web publication