Skip to content

Commit

Permalink
Make this elsable
Browse files Browse the repository at this point in the history
Fixes #263
  • Loading branch information
hroncok committed Aug 26, 2018
1 parent 2e545b6 commit dac0045
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 236 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -32,3 +32,7 @@ pip-log.txt
/cache/
.cache
.pytest_cache/

# Elsa
_build/
/talks-archive/
15 changes: 10 additions & 5 deletions .travis.yml
Expand Up @@ -6,15 +6,20 @@ install:
- "pip install .[tests]"
script:
- "pytest"
- "test $TRAVIS_PULL_REQUEST == false || export DISABLE_GITHUB_ISSUES_FETCH=true"
- "python runserver.py freeze"
after_success:
- "coveralls"
deploy:
provider: "script"
script: "deployment/deploy.sh"
provider: script
skip_cleanup: true
script: 'python runserver.py deploy --no-freeze --push'
on:
branch: "master"
python: "3.4"
repo: "pyvec/python.cz"
branch: master
repo: pyvec/python.cz
notifications:
slack:
secure: "s/PCU4+geUozmw3AJguPYpv/YFNZVYmQ30A3DZpbSOE/9HDEgqbaF/hONY1VhHriRBG1EJ2uSezbxjOveyJPV+UMGJFMPU4c4Mw4AHxyROSnJe/MpOKPd8QRgbtYWYwy5UI47bzxotGoN49Mk0EjqhaFk9DFb14et9YPwMDbrVY="
env:
global:
secure: R1+KSJV1oOikNBvyil0m/FMace5Y4lVC8WTlIpspZZ30BDkJCQ0eTnXy7gFvuEa4wBmVSqRKnRm+LKf44wXRjyKy/KRwUIzuy9AmzzQMe/PuvWSQDz7zf1dvG7GlR0kTJlgJ7s0+Vh4uqEpjIQnvtn+xkLguYVs3QXmTUvxLMnA=
13 changes: 4 additions & 9 deletions README.md
Expand Up @@ -20,22 +20,17 @@ The site uses GitHub API. For certian pages to work correctly, you need to set t

```sh
$ export GITHUB_TOKEN=...
$ python runserver.py
$ python runserver.py --help
```

### Deployment

The site gets automatically deployed after any push to the `master` branch. See [documentation in the `deployment` directory](deployment/README.md).

- **Hosting:** [Rosti.cz](https://rosti.cz/)<br>
Access: [Pyvec](http://pyvec.org/)
The site gets automatically deployed after any push to the `master` branch.
It is frozen by [Elsa](https://github.com/pyvec/elsa). A cron job redeploys
it daily, so any content of dynamic nature isn't outdated.

- **Domain:** bestowed by [KRAXNET](http://www.kraxnet.cz/)<br>
Access: e-mail request to [KRAXNET](http://www.kraxnet.cz/)

- **Monitoring:** [UptimeRobot](https://uptimerobot.com/)<br>
Access: [@honzajavorek](http://github.com/honzajavorek)

- **Analytics:** [Google Analytics](http://www.google.com/analytics/)<br>
Access: [@honzajavorek](http://github.com/honzajavorek), [@encukou](http://github.com/encukou), [@martinbilek](http://github.com/martinbilek), [@benabraham](http://github.com/benabraham)

Expand Down
102 changes: 0 additions & 102 deletions deployment/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions deployment/deploy.sh

This file was deleted.

Binary file removed deployment/id_rsa_pyvec_deployment.enc
Binary file not shown.
28 changes: 0 additions & 28 deletions deployment/update.sh

This file was deleted.

4 changes: 4 additions & 0 deletions pythoncz/__init__.py
@@ -1,6 +1,7 @@
import os

from flask import Flask
from flask_frozen import Freezer


ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')
Expand All @@ -27,6 +28,9 @@


app = Flask('pythoncz')

freezer = Freezer(app)

app.config.from_object(__name__)


Expand Down
1 change: 0 additions & 1 deletion pythoncz/templates/_base.html
Expand Up @@ -112,7 +112,6 @@
href="mailto:info&#64;pyvec.org">info&#64;<!---->pyvec.org</a>, tweetujte na <a href="https://twitter.com/pyvec">@pyvec</a>.
<br>
Ilustrace kreslí <a href="http://honzajavorek.cz">Honza Javorek</a>.
Stránky hostujeme zdarma u <a href="https://rosti.cz">Roští.cz</a>.
Doménu python.cz zapůjčil <a href="http://xnet.cz/">KRAXNET</a>.
Děkujeme!
</p>
Expand Down
19 changes: 19 additions & 0 deletions pythoncz/templates/meta_redirect.html
@@ -0,0 +1,19 @@
{% extends '_base.html' %}
{% block head %}
<!-- Apologies for using deprecated HTML technology -->
<meta http-equiv="refresh" content="0; {{ url }}">
<link rel="canonical" href="{{ url }}">
<meta name="robots" content="noindex, follow">
{% endblock %}

{% block content %}
<h1>Přesměrování</h1>
<div class="row">
<div class="col-md-8 col-md-offset-2 thumbnail">
<p>
Obsah této stránky byl přesunut na novou adresu:
<a href="{{ url }}">{{ url }}</a>.
</p>
</div>
</div>
{% endblock %}
95 changes: 80 additions & 15 deletions pythoncz/views.py
@@ -1,9 +1,12 @@
import os
import subprocess
from fnmatch import fnmatch
from urllib.parse import quote_plus as url_quote_plus

from flask import (render_template as _render_template, url_for,
redirect, request, make_response)
request, make_response, send_from_directory)

from pythoncz import app
from pythoncz import app, freezer
from pythoncz.models import jobs, photos, beginners, github


Expand Down Expand Up @@ -65,26 +68,31 @@ def jobs_en():

@app.route('/zapojse/')
def get_involved_cs():
disabled = os.getenv('DISABLE_GITHUB_ISSUES_FETCH', False)
try:
if disabled:
raise Exception('DISABLE_GITHUB_ISSUES_FETCH is set')
issues = github.get_issues(app.config['GITHUB_ORGANIZATIONS'])
return render_template('get_involved_cs.html', issues=issues)
except Exception as e:
template = render_template('get_involved_cs.html', issues=[], error=e)
return make_response(template, 500)
code = 200 if disabled else 500
return make_response(template, code)


# Subdomain redirect

@app.route('/', subdomain='www')
def subdomain_redirect():
return redirect(url_for('index_cs'))
# Redirects of legacy stuff

def redirect(url, code=None):
"""Return a response with a Meta redirect, code is unused"""

# Redirects of legacy stuff
# With static pages, we can't use HTTP redirects.
# Return a page wit <meta refresh> instead.
#
# When Frozen-Flask gets support for redirects
# (https://github.com/Frozen-Flask/Frozen-Flask/issues/81),
# this should be revisited.

@app.route('/index.html')
def index_legacy():
return redirect(url_for('index_cs'), code=301)
return render_template('meta_redirect.html', url=url)


@app.route('/english.html')
Expand All @@ -97,12 +105,69 @@ def pyladies(target):
return redirect('http://pyladies.cz/v1/' + target, code=301)


@freezer.register_generator
def pyladies():
# This is hardcoded because it doesn't change & it's easier to hardcode it
targets = (
's001-install/',
's002-hello-world/',
's003-looping/',
's004-strings/',
's005-modules/',
's006-lists/',
's007-cards/',
's008-cards2/',
's009-git/',
's010-data/',
's011-dicts/',
's012-pyglet/',
's014-class/',
's015-asteroids/',
's016-micropython/',
)
yield from ({'target': t} for t in targets)


@app.route('/pyladies/')
def pyladies_index():
return redirect('http://pyladies.cz', code=301)
return redirect('http://pyladies.cz/', code=301)


# Talks, this used to redirect, but that's not possible with *.pdf HTML files
talks_dir = 'talks-archive'


@app.before_first_request
def clone_talks():
try:
os.chdir(talks_dir)
except FileNotFoundError:
subprocess.run(('git', 'clone',
'https://github.com/pyvec/talks-archive',
'--depth', '1'))
os.chdir(talks_dir)
else:
subprocess.run(('git', 'fetch', 'origin'), check=True)
subprocess.run(('git', 'reset', '--hard', 'origin/master'), check=True)
finally:
os.chdir('..')


@app.route('/talks/<path:target>')
def talks(target):
base_url = 'https://github.com/pyvec/talks-archive/raw/master/'
return redirect(base_url + target, code=301)
# sends from pythoncz directory, hence ../
return send_from_directory(f'../{talks_dir}', target)


@freezer.register_generator
def talks():
ignore = ['.travis.yml', '.gitignore']
for name, dirs, files in os.walk(talks_dir):
if '.git' in dirs:
dirs.remove('.git')
for file in files:
if file == '.git':
continue
if not any(fnmatch(file, ig) for ig in ignore):
path = os.path.relpath(os.path.join(name, file), talks_dir)
yield {'target': path}

0 comments on commit dac0045

Please sign in to comment.