Skip to content
Permalink
Browse files

Use Python assignments as a staff configuration format

/hmm/
  • Loading branch information...
charmander committed Jul 7, 2018
1 parent b4ea6a1 commit 815f4d351c1ff372c8826bc05478a69cb39299ed
@@ -14,7 +14,7 @@
/static/media
/static/SHARE
/config/site.config.txt
/config/weasyl-staff.yaml
/config/weasyl-staff.py
/.vagrant
/weasyl-env
/twistd.pid
@@ -35,8 +35,8 @@ config/site.config.txt:
cp -n config/site.config.txt.example $@

# Staff
config/weasyl-staff.yaml:
cp -n config/weasyl-staff.yaml.example $@
config/weasyl-staff.py:
cp -n config/weasyl-staff.example.py $@

# Creates python environment
$(VE): etc/requirements.txt
@@ -85,7 +85,7 @@ build/rev-manifest.json: node_modules

# Phony setup target
.PHONY: setup
setup: $(VE) config/site.config.txt config/weasyl-staff.yaml build/rev-manifest.json $(STATIC_DIRS) $(TEMP_DIRS)
setup: $(VE) config/site.config.txt config/weasyl-staff.py build/rev-manifest.json $(STATIC_DIRS) $(TEMP_DIRS)

# Phony deploy targets
.PHONY: deploy deploy-web-worker
@@ -0,0 +1,40 @@
# Members of Weasyl staff.
#
# This file is a temporary solution for testing and deployment. It
# should be replaced in production with a file generated from ansible
# and in development environments with a static file downloaded
# alongside the sample database.

directors = [
1014, # Fiz
23613, # Hendikins
2061, # Ikani
2402, # SkylerBunny
5, # Taw
2008, # Tiger
]

technical_staff = [
5173, # Keet
]

admins = [
3, # Kihari
2011, # MLR
20418, # Novacaine
]

mods = [
61554, # ChaosCalix
15712, # Levi
89199, # Menageriecat
2252, # SuburbanFox
]

developers = [
38623, # 8BitFur
1019, # Aden
34165, # Charmander
15224, # Foximile
5756, # Weykent
]

This file was deleted.

@@ -14,8 +14,8 @@ To write a new tool using libweasyl (assuming you already have your database
setup and libweasyl's requirements installed in your python environment), you
probably should begin by setting up a call to [`configure_libweasyl()`]
(libweasyl/configuration.py). At minimum this will require a SQLAlchemy
`scoped_session` to your weasyl database and a path to a staff.yaml file
identifying the staff users.
`scoped_session` to your weasyl database and a staff dict identifying
the staff users.


Testing and Style Checks
@@ -34,7 +34,6 @@
'oauthlib==2.0.4',
'psycopg2cffi==2.7.7',
'pytz==2018.4',
'pyyaml==3.12',
'sanpera==0.1.1+weasyl.6', # https://github.com/Weasyl/sanpera
'sqlalchemy==1.2.9',
'translationstring==1.3',
@@ -170,7 +170,7 @@ def MACRO_MOD_ACTIONS_FOR_SETTINGS(settings, submission_type):
MACRO_SYS_LOG_PATH = os.path.join(MACRO_STORAGE_ROOT, "log/")
MACRO_SYS_TEMP_PATH = os.path.join(MACRO_STORAGE_ROOT, "temp/")
MACRO_SYS_CONFIG_PATH = os.path.join(MACRO_APP_ROOT, "config/")
MACRO_SYS_STAFF_CONFIG_PATH = os.path.join(MACRO_SYS_CONFIG_PATH, "weasyl-staff.yaml")
MACRO_SYS_STAFF_CONFIG_PATH = os.path.join(MACRO_SYS_CONFIG_PATH, "weasyl-staff.py")

MACRO_BLANK_THUMB = "/static/images/default-thumbs/visual.png"
MACRO_DEFAULT_SUBMISSION_THUMBNAIL = [

This file was deleted.

@@ -0,0 +1,41 @@
"""
Retrieve a dictionary of Weasyl staff.
"""

from __future__ import absolute_import

import ast

from weasyl import macro


def load():
"""
Load staff from a Python config file.
Parameters: None. Path is obtained from `macro.MACRO_SYS_STAFF_CONFIG_PATH`
Returns:
staff_dict: A dictionary with the staff member user IDs.
"""
with open(macro.MACRO_SYS_STAFF_CONFIG_PATH) as f:
source = f.read()

module = ast.parse(source)
staff = {}

for statement in module.body:
if not isinstance(statement, ast.Assign):
raise SyntaxError("Unexpected node in staff configuration")

target = statement.targets[0]

if len(statement.targets) != 1 or not isinstance(target, ast.Name):
raise SyntaxError("Unexpected assignment target in staff configuration")

if target.id not in {"directors", "technical_staff", "admins", "mods", "developers"}:
raise SyntaxError("Unexpected key in staff configuration: %r" % (target.id,))

staff[target.id] = ast.literal_eval(statement.value)

return staff
@@ -10,7 +10,7 @@
import weasyl.macro as m
from weasyl.media import format_media_link
import weasyl.middleware as mw
from weasyl import read_staff_yaml
from weasyl import staff_config


# Get a configurator and register some tweens to handle cleanup, etc.
@@ -61,6 +61,6 @@ def weasyl_404(request):
dbsession=d.sessionmaker,
not_found_exception=HTTPNotFound,
base_file_path=m.MACRO_STORAGE_ROOT,
staff_config_dict=read_staff_yaml.load_staff_dict(),
staff_config_dict=staff_config.load(),
media_link_formatter_callback=format_media_link,
)

0 comments on commit 815f4d3

Please sign in to comment.
You can’t perform that action at this time.