From f6cf02bcaf7ec064035d69eb577c71317c3f57f4 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 27 Jan 2021 17:03:24 -0600 Subject: [PATCH] Add basic win32 support for dev bootstrap --- dev/bootstrap.py | 26 +++++++++++++++++------ dev/rattail.conf | 10 ++++----- dev/tasks.py | 54 +++++++++++++++++++++++++++++++++++++++++------- dev/web.conf | 4 ++-- 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/dev/bootstrap.py b/dev/bootstrap.py index 4056851..6400216 100644 --- a/dev/bootstrap.py +++ b/dev/bootstrap.py @@ -12,10 +12,13 @@ here = os.path.abspath(os.path.dirname(__file__)) def bootstrap(): - if not inside_virtualenv(): return + # install wheel + subprocess.run(['pip', 'install', 'wheel'], + check=True) + # install invoke, sphinx subprocess.run(['pip', 'install', 'invoke', 'Sphinx'], check=True) @@ -23,7 +26,10 @@ def bootstrap(): # run bootstrap task os.chdir(here) try: - completed = subprocess.run(['invoke', '--echo', 'bootstrap']) + if sys.platform == 'win32': + completed = subprocess.run(['invoke', 'bootstrap']) + else: + completed = subprocess.run(['invoke', '--echo', 'bootstrap']) except KeyboardInterrupt: sys.exit(130) # 128 + SIGINT else: @@ -33,10 +39,18 @@ def bootstrap(): def inside_virtualenv(): if not (hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)): - print("\nNot running inside a virtual environment!\n\n" - "Please create and activate that first, e.g. like:\n\n" - " python -m venv /srv/envs/theo\n" - " source /srv/envs/theo/bin/activate\n") + print("") + print("Not running inside a virtual environment!") + print("") + print("Please create and activate that first, e.g. like:") + print("") + if sys.platform == 'win32': + print(" py -m venv C:\\envs\\theo") + print(" C:\\envs\\theo\\Scripts\\activate.bat") + else: + print(" python -m venv /srv/envs/theo") + print(" source /srv/envs/theo/bin/activate") + print("") return False return True diff --git a/dev/rattail.conf b/dev/rattail.conf index 5cb4dec..5db994b 100644 --- a/dev/rattail.conf +++ b/dev/rattail.conf @@ -12,9 +12,9 @@ [rattail] timezone.default = America/Chicago -datadir = /app/data -batch.files = /app/data/batch -workdir = /app/work +datadir = appdata +batch.files = appdatabatch +workdir = appwork [rattail.config] # include = /etc/rattail/rattail.conf @@ -39,7 +39,7 @@ default.to = root@localhost pictures.gtin.root_url = https://rattailproject.org/pod/pictures/gtin [rattail.upgrades] -files = /app/data/upgrades +files = appdataupgrades ############################## # alembic @@ -106,7 +106,7 @@ handlers = [handler_file] class = handlers.RotatingFileHandler -args = ('/app/log/rattail.log', 'a', 1000000, 100, 'utf_8') +args = (r'applograttail.log', 'a', 1000000, 100, 'utf_8') formatter = generic [handler_console] diff --git a/dev/tasks.py b/dev/tasks.py index f00ce20..2ef8c11 100644 --- a/dev/tasks.py +++ b/dev/tasks.py @@ -47,7 +47,10 @@ def bootstrap(c): print("start your development web app with this command:") print() print(" cd {}".format(envdir)) - print(" bin/pserve --reload file+ini:app/web.conf") + if sys.platform == 'win32': + print(r" Scripts\pserve --reload file+ini:app\web.conf") + else: + print(" bin/pserve --reload file+ini:app/web.conf") print() print("then check out your development web app at:") print() @@ -100,7 +103,10 @@ def upgrade_pip(c): """ Upgrade pip and friends """ - c.run('pip install -U pip') + if sys.platform == 'win32': + c.run('python -m pip install -U pip') + else: + c.run('pip install -U pip') c.run('pip install -U setuptools wheel') @@ -119,7 +125,13 @@ def make_appdir(c, envdir): """ appdir = os.path.join(envdir, 'app') if not os.path.exists(appdir): - c.run('{} make-appdir'.format(os.path.join(envdir, 'bin', 'rattail'))) + if sys.platform == 'win32': + c.run('{} make-appdir --path {}'.format( + os.path.join(envdir, 'Scripts', 'rattail'), + appdir)) + else: + c.run('{}/bin/rattail make-appdir --path {}'.format( + envdir, appdir)) return appdir @@ -132,6 +144,7 @@ def make_configs(c, envdir, appdir, info): with open('rattail.conf') as f: contents = f.read() contents = contents.replace('', envdir) + contents = contents.replace('', os.sep) contents = contents.replace('', info['dbhost']) contents = contents.replace('', info['dbname']) contents = contents.replace('', info['dbuser']) @@ -141,13 +154,20 @@ def make_configs(c, envdir, appdir, info): # quiet.conf if not os.path.exists(os.path.join(appdir, 'quiet.conf')): - c.run('{}/bin/rattail make-config -T quiet -O {}'.format(envdir, appdir)) + if sys.platform == 'win32': + c.run('{} make-config -T quiet -O {}'.format( + os.path.join(envdir, 'Scripts', 'rattail'), + appdir)) + else: + c.run('{}/bin/rattail make-config -T quiet -O {}'.format( + envdir, appdir)) # web.conf if not os.path.exists(os.path.join(appdir, 'web.conf')): with open('web.conf') as f: contents = f.read() contents = contents.replace('', envdir) + contents = contents.replace('', os.sep) with open(os.path.join(appdir, 'web.conf'), 'w') as f: f.write(contents) @@ -156,19 +176,37 @@ def check_db(c, envdir, appdir): """ Do basic sanity checks for Theo database """ - c.run('{}/bin/rattail -c {}/quiet.conf --no-versioning checkdb'.format(envdir, appdir)) + if sys.platform == 'win32': + c.run('{} -c {} --no-versioning checkdb'.format( + os.path.join(envdir, 'Scripts', 'rattail'), + os.path.join(appdir, 'quiet.conf'))) + else: + c.run('{}/bin/rattail -c {}/quiet.conf --no-versioning checkdb'.format( + envdir, appdir)) def install_db_schema(c, envdir, appdir): """ Install the schema for Theo database """ - c.run('{}/bin/alembic -c {}/rattail.conf upgrade heads'.format(envdir, appdir)) + if sys.platform == 'win32': + c.run('{} -c {} upgrade heads'.format( + os.path.join(envdir, 'Scripts', 'alembic'), + os.path.join(appdir, 'rattail.conf'))) + else: + c.run('{}/bin/alembic -c {}/rattail.conf upgrade heads'.format( + envdir, appdir)) def make_admin_user(c, envdir, appdir, info): """ Make an admin user in the Theo database """ - c.run('{}/bin/rattail -c {}/quiet.conf make-user --admin {} --password {}'.format( - envdir, appdir, info['theouser'], info['theopass'])) + if sys.platform == 'win32': + c.run('{} -c {} make-user --admin {} --password {}'.format( + os.path.join(envdir, 'Scripts', 'rattail'), + os.path.join(appdir, 'quiet.conf'), + info['theouser'], info['theopass'])) + else: + c.run('{}/bin/rattail -c {}/quiet.conf make-user --admin {} --password {}'.format( + envdir, appdir, info['theouser'], info['theopass'])) diff --git a/dev/web.conf b/dev/web.conf index a00b7e7..f95690a 100644 --- a/dev/web.conf +++ b/dev/web.conf @@ -11,7 +11,7 @@ ############################## [rattail.config] -include = %(here)s/rattail.conf +include = %(here)srattail.conf ############################## @@ -53,4 +53,4 @@ port = 9080 level = INFO [handler_file] -args = ('/app/log/web.log', 'a', 1000000, 100, 'utf_8') +args = (r'applogweb.log', 'a', 1000000, 100, 'utf_8')