File: mergeall-products/unzipped/test/ziptools/_publish.sh

#===================================================================
# Automatically build+publish this folder's content, only.
#
# This builds the stand-alone ziptools distribution.  Mergeall's
# source package also includes ziptools as an embedded component.
#
# Launch this script from Terminal in its own folder, with:
#     cd $C/mergeall/test/ziptools
#     bash _publish.sh
#
# NOT run by $W/_admin/BUILD-THUMBSPAGE-CLIENTS/_PUBLISH.sh:
# no thumbspage galleries here.
#
# This app has no separate build/ folder: this IS its build script.
# See example output in doctetc/, and edit here for other hosts.
#
# Mergeall script ../fix-nonportable-filenames.py is automatically 
# copied here with a custom 'Status:' header line, so it's always 
# up to date; it's useful before zips, and counted in __sloc__.py.
# ziptools and Mergeall now both ignore __pycache__; not added here.
#===================================================================

# get common defs
source ~/MY-STUFF/Websites/_admin/BUILD-THUMBSPAGE-CLIENTS/common.sh

# caution: run __sloc.py__ first if code changed


#------------------------------------------
# 1) Zip ziptools (self) in Code
#------------------------------------------

cd $C/mergeall/test
mv ziptools/__private__ $temp

# copy mergeall's fixer script, and mod its status line
cp ../fix-nonportable-filenames.py ziptools
repl='Status:   this script is copied here from Mergeall, learning-python.com/mergeall'
sed -i '' -e "s@Status:.*@$repl@" ziptools/fix-nonportable-filenames.py

py3 $Z/zip-create.py ziptools.zip ziptools -skipcruft    # this is what users get (test READMEs)
mv $temp/__private__ ziptools


#------------------------------------------
# 2) Unzip in Websites/../Complete/ziptools
#------------------------------------------

cd $W/Programs/Current/Complete/ziptools                 # this has its own .htaccess
rm -rf ziptools*                                         # nested ziptools/ziptools
cp -p $C/mergeall/test/ziptools.zip .
mv $C/mergeall/test/ziptools.zip $Z/__private__/ziptools--$stamp.zip

py3 $Z/zip-extract.py ziptools.zip . -permissions        # makes ziptools subdir here, alongside zip

# already has, but may change [has no more!]
py3 $M/insert-analytics.py ziptools/_README.html


#------------------------------------------
# 3) Publish to local UNION and zip there
#------------------------------------------

# copies README=>_README; would add ip-anon line to .htaccess but did manually; tweaks analytics
cd $W
py3 _PUBLISH.py | tail -n 20
cd UNION

py3 $Z/zip-create.py ziptools.zip ziptools -skipcruft    # ziptools/{ziptools.zip, ziptools/} 


#--------------------------------------------
# 4) Upload to and unzip in website's root
#--------------------------------------------

SCP ziptools.zip htdocs
echo '# Could run ziptools on the server too, but demo interoperability'

# unzip at site
SSH <<-EOF
	cd htdocs                                            # site root
	rm -rf ziptools                                      # entire top-level folder; or via filezilla
	unzip -d . ziptools.zip                              # recreates top ziptools/ folder: ziptools/{ziptools.zip, ziptools/}
	rm ziptools.zip                                      # top (root level) zip, not the nested one!
	exit
	# keep .zip and unzipped content in top ziptools/
	EOF

rm ziptools.zip   # in local UNION


#--------------------------------------------
# 5) Download and verify zip: live to local 
#--------------------------------------------

cd $temp
rm -rf _README.html ziptools.zip ziptools diffallz

# content
printf '\n** Diff: there should 1 diff in README: analytics\n'
curl -O https://learning-python.com/ziptools/ziptools/_README.html
diff _README.html $Z/_README.html

# zipfile
printf '\n** Cmp: there should be no cmp output for zip\n'
curl -O https://learning-python.com/ziptools/ziptools.zip
cmp -bl ziptools.zip $Z/__private__/ziptools--$stamp.zip

# unzippped content
py3 $Z/zip-extract.py ziptools.zip . > /dev/null    # makes ziptools/

printf '\n** Diffall: there should be 1 for unzip = private/\n'
py3 $C/mergeall/diffall.py ziptools $Z -skipcruft > diffallz
tail -n 7 diffallz

printf '\n** Diffall: there should be 1 unique = private/\n'
grep --context=4 '*UNIQ' diffallz

printf '\n** Mergeall: there should be 1 unique from = private/\n'
py3 $C/mergeall/mergeall.py $Z ziptools -skipcruft -report | tail -n 9

# keep to eyeball: rm -rf _README.html zipfile.zip zipfile diffallz
echo 'Bye.'



[Home page] Books Code Blog Python Author Train Find ©M.Lutz