File: pygadgets-products/unzipped/build/build-source/build.py
#!/usr/bin/env python3 """ ============================================================================= Make a pygadgets 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. *NOTE*: remove any unzipped app/exe folders in build/ before running this. ============================================================================= """ 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 in build-app-exe on the Mac (or elsewhere) #---------------------------------------------------------------------------- # copy pygadgets to avoid accidents and recursive-copy loop #---------------------------------------------------------------------------- # automated setup - run in this file's dir if sys.platform.startswith('darwin'): temp = '/Users/blue/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 print('Building tree') shutil.copytree(join('..', '..', '..', 'pygadgets'), join(temp, 'pygadgets'), symlinks=True) #---------------------------------------------------------------------------- # make the source zipfile #---------------------------------------------------------------------------- # zip command: use portable ziptools (vs: 'zip -r %s %s' % (thezip, thedir)) thedir = 'PyGadgets-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 shutil.move(join(temp, 'pygadgets'), join(temp, thedir)) if os.path.exists(thedir): shutil.rmtree(thedir) # nuke bogus retained temp? shutil.move(join(temp, thedir), '.') shutil.rmtree(temp) # rm temp build tree # remove zipped app, exes, src in the build tree for space for (root, subs, files) in os.walk(join(thedir, 'build')): for file in files: if file.startswith(('PyGadgets', 'prev-PyGadgets')) 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 non-public stuff print('Removing __private__, __pycache__') shutil.rmtree(join(thedir, '__private__')) shutil.rmtree(join(thedir, '__pycache__')) # 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