Add basic win32 support for dev bootstrap

This commit is contained in:
Lance Edgar 2021-01-27 17:03:24 -06:00
parent 4980e5784b
commit f6cf02bcaf
4 changed files with 73 additions and 21 deletions

View file

@ -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,6 +26,9 @@ def bootstrap():
# run bootstrap task
os.chdir(here)
try:
if sys.platform == 'win32':
completed = subprocess.run(['invoke', 'bootstrap'])
else:
completed = subprocess.run(['invoke', '--echo', 'bootstrap'])
except KeyboardInterrupt:
sys.exit(130) # 128 + SIGINT
@ -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

View file

@ -12,9 +12,9 @@
[rattail]
timezone.default = America/Chicago
datadir = <ENVDIR>/app/data
batch.files = <ENVDIR>/app/data/batch
workdir = <ENVDIR>/app/work
datadir = <ENVDIR><SEP>app<SEP>data
batch.files = <ENVDIR><SEP>app<SEP>data<SEP>batch
workdir = <ENVDIR><SEP>app<SEP>work
[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 = <ENVDIR>/app/data/upgrades
files = <ENVDIR><SEP>app<SEP>data<SEP>upgrades
##############################
# alembic
@ -106,7 +106,7 @@ handlers =
[handler_file]
class = handlers.RotatingFileHandler
args = ('<ENVDIR>/app/log/rattail.log', 'a', 1000000, 100, 'utf_8')
args = (r'<ENVDIR><SEP>app<SEP>log<SEP>rattail.log', 'a', 1000000, 100, 'utf_8')
formatter = generic
[handler_console]

View file

@ -47,6 +47,9 @@ def bootstrap(c):
print("start your development web app with this command:")
print()
print(" cd {}".format(envdir))
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:")
@ -100,6 +103,9 @@ def upgrade_pip(c):
"""
Upgrade pip and friends
"""
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>', envdir)
contents = contents.replace('<SEP>', os.sep)
contents = contents.replace('<DBHOST>', info['dbhost'])
contents = contents.replace('<DBNAME>', info['dbname'])
contents = contents.replace('<DBUSER>', 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>', envdir)
contents = contents.replace('<SEP>', 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
"""
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']))

View file

@ -11,7 +11,7 @@
##############################
[rattail.config]
include = %(here)s/rattail.conf
include = %(here)s<SEP>rattail.conf
##############################
@ -53,4 +53,4 @@ port = 9080
level = INFO
[handler_file]
args = ('<ENVDIR>/app/log/web.log', 'a', 1000000, 100, 'utf_8')
args = (r'<ENVDIR><SEP>app<SEP>log<SEP>web.log', 'a', 1000000, 100, 'utf_8')