File: thumbspage/build/x-publish-external-demos-prod/_PUBLISH.py

#!/usr/bin/env python3
"""
=======================================================================
Build+publish all thumbspage external website clients, automatically.

USAGE
-----
On changes in thumbspage which modify the galleries it generates:

1) Run thumbspage's own build/_PUBLISH.sh, to build+publish 
   all of its internal gallery examples.

2) Run this to update all external-client dependents, with command
   line 'python3 _PUBLISH.py' in Terminal.

This script in turn runs a _publish.sh script in each client's folder.
Run either this to publish all thumbspage external clients, or run a 
single client's _publish.sh in its folder to publish just that client.

Run me anywhere, no arguments: changes directories to absolute paths.
For each client, generates galleries, zips, uploads, and unzips on
server, inserting analytics and performing any demo-specific steps.

ROLES
-----
All products built here include thumbspage galleries, and require
updates on changes in thumbspage results.  Due to this website's 
history, however, the roles of this script are somewhat uneven.
  
For some clients (apps), this makes just galleries, not the full 
product; for these, clients have a separate build/ folder which is
either used separately, or includes a different _publish.sh for 
full builds.  Some clients are also built in full here, along with 
their galleries, but products without galleries are not built here.

NOTES
-----
This is Python for better coding; product build scripts are Bash.
An early Bash version of this script was moved to miscellany/
(and may be arbitrarily out of sync by the time you open it).
 
This is a mod of thumbspage's build/x-publish-external-demos.sh
demo, and is the version actually used.  The original's steps are 
split off to separate scripts in individual client folders, to 
support single-part builds (much like the per-folder _generate.sh
scripts in generate-examples.py).  The client scripts source common 
setup code in ./common.sh, and this is just a top-level controller.

Caveat: as coded, the site's top-level _PUBLISH script is run by 
each client script here (N runs for N clients), copying the site
to UNION in full each time.  To do better, each client's script 
could be split into pre- and post-publish steps; that complexity 
isn't justified, given that the site build takes just 12 seconds. 
=======================================================================
"""

import os, sys, time

Pause = False   # stop for enter or ctrl-c between examples?

# caveat: redundant with common.sh
Web  = os.environ['HOME'] + '/MY-STUFF/Websites'
Code = os.environ['HOME'] + '/MY-STUFF/Code'


#----------------------------------------------------------------
# Program logic
#----------------------------------------------------------------

def announce(product): 
    print('\n\n' + '@'*60 + '\n' + product)
    if Pause: 
        try:
            input('Press enter/return to continue')
        except KeyboardInterrupt:
            print('\nRun aborted.')
            sys.exit()
    print('@'*60)


def publish(product, folder):
    announce(product)
    os.chdir(folder)
    os.system('bash _publish.sh')

def publish_all(products):
    for (product, folder) in products:
        publish(product, folder)


# table of (display-label, script-path)
PRODUCTS = [


#----------------------------------------------------------------
# Gallery-only products: no separate html, in own folders
#----------------------------------------------------------------

('trnpix',
  Web + '/Posts/Current/Complete/trnpix'),

('gadgets',
  Web + '/Programs/Current/Complete/gadgets'),

('site-mobile-screenshots',
  Web + '/Posts/Current/Complete/site-mobile-screenshots'),   # with config edits

('tiobeindex',
  Web + '/Posts/Current/Complete/tiobe-language-rankings-aug2019'),

# items omitted here


#----------------------------------------------------------------
# Doc products, html + gallery(s): complete builds, run in ..
#----------------------------------------------------------------

('android-tkinter',
  Code + '/android-tkinter'),

('mergeall-android-scripts',
  Code + '/mergeall/mergeall-android-scripts'),

('mergeall-android11-updates',
  Web + '/Programs/Current/Complete/mergeall-android11-updates-media'),


#----------------------------------------------------------------
# App screenshots: online subfolder of pkg only, separate build/
#----------------------------------------------------------------

('frigcal-screenshots',
  Code + '/frigcal/docetc/docimgs'),

('mergeall-screenshots',
  Code + '/mergeall/docetc/docimgs'),

('pyedit-screenshots',
  Code + '/pyedit/TextEditor/docetc/docimgs'),

('pymailgui-screenshots',
  Code + '/pymailgui/docetc/docimgs'),

('pygadgets-screenshots',
  Code + '/pygadgets/screenshots'),

('tagpix-screenshots',
  Code + '/tagpix/screenshots'),

# OR complete build, not just screenshots
#
# ('tagpix-full-build',
#   Code + '/tagpix/build'),


#----------------------------------------------------------------
# Other galleries: complete build, no separate build/ folder
#----------------------------------------------------------------

('shrinkpix',
  Code + '/shrinkpix'),


#----------------------------------------------------------------
# No thumbspage galleries: complete build, no build/ folder
#----------------------------------------------------------------

# NOT RUN HERE
#
# ('ziptools',
#  Code + '/mergeall/test/ziptools'),


# Others TBD: genhtml, etc.; thumbspage is built in full elsewhere
]


#----------------------------------------------------------------
# Build those products
#----------------------------------------------------------------

if __name__ == '__main__':
    print('External builds starting at:', time.asctime())
    publish_all(PRODUCTS)
    print('\nExternal builds stopping at:', time.asctime())



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