Skip to content

Commit 553b93f

Browse files
committed
Create project management command
1 parent b866523 commit 553b93f

File tree

6 files changed

+123
-5
lines changed

6 files changed

+123
-5
lines changed

TODO.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
- Split up README into several files
55
- Properly verify all settings
66
- Write documentation (readthedocs)
7+
- Make EffectControllers
8+
- SingleEffectController
9+
- TrackSystemEffectController
10+
- SimpleTimeLineEffectController
711
- CLI tool creating new projects and effects.
812
- Create more examples in demosys_test
913
- Shaders
14+
- Improve error prints (use actual source from GL so we can see expanded typedefs)
1015
- Core loader support for common formats
1116
- Custom loader support / less hacky loading
1217
Textures:
13-
- Support 1D and 3D textures
14-
- Custom texture loaders
18+
- 1D and 3D
19+
- Texture Array
20+
- Texture Cube
21+
- Custom texture loaders
1522
- FBOs
1623
- Support layers
1724
Generic Data:
@@ -25,4 +32,5 @@ Generic Data:
2532
- FBOs
2633
- Textures
2734
- Settings entry for key bindings
28-
- Clean up cotroller/initialization
35+
- Clean up controller/initialization
36+
- Look into using freetype

demosys/conf/default_settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Default settings for demosys. Override using a settings module.
33
"""
44

5+
# What attributes should be used when generating a settings file
6+
__ORDER__ = ('DEBUG', 'SCREENSHOT_PATH', 'OPENGL', 'WINDOW', 'EFFECTS', 'MUSIC',
7+
'SHADER_DIRS', 'SHADER_FINDERS', 'TEXTURE_DIRS', 'TEXTURE_FINDERS')
8+
59
DEBUG = False
610

711
SCREENSHOT_PATH = None

demosys/conf/settingsfile.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
def create(settings):
4+
"""
5+
Return a string representation of the settings.
6+
This is an extremely ugly way of doing this, but it works for now!
7+
"""
8+
# FIXME: Use a template system for generating settings file
9+
data = "# Auto generated settings file\n" \
10+
"import os\n" \
11+
"PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))\n\n"
12+
for name in settings.__ORDER__:
13+
value = getattr(settings, name)
14+
if isinstance(value, dict):
15+
value = ",\n".join(' "{}": {}'.format(k, to_s(v)) for k, v in value.items())
16+
data += "%s = {\n%s\n}\n\n" % (name, value)
17+
elif isinstance(value, tuple):
18+
value = ",\n".join(" {}".format(to_s(v)) for v in value)
19+
data += f"{name} = (\n{value})\n\n"
20+
21+
return data
22+
23+
24+
def to_s(t):
25+
if isinstance(t, str):
26+
return f'"{t}"'
27+
else:
28+
return str(t)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# FIXME: Rewrite this into something less horrible in the future
2+
# Right now we just want this to work
3+
import os
4+
from importlib import import_module
5+
6+
HELP = "Create a project"
7+
8+
9+
def print_usage():
10+
print("Usage:")
11+
print(" crateproject <name>")
12+
13+
14+
def run(args):
15+
if not args:
16+
print_usage()
17+
return
18+
19+
name = args[0]
20+
print(f"Creating project '{name}'")
21+
22+
# Check for python module collision
23+
try:
24+
import_module(name)
25+
except ImportError:
26+
pass
27+
else:
28+
raise ValueError(f"{name} conflicts with an existing python module")
29+
30+
# Is the name a valid identifier?
31+
validate_name(name)
32+
33+
# Make sure we don't mess with existing directories
34+
if os.path.exists(name):
35+
print(f"Directory {name} already exist. Aborting.")
36+
return
37+
38+
# Create the project directory
39+
os.makedirs(name)
40+
41+
# Use the default settings file
42+
os.environ['DEMOSYS_SETTINGS_MODULE'] = 'demosys.conf.default_settings'
43+
from demosys.conf import settings
44+
from demosys.conf import settingsfile
45+
46+
with open(os.path.join(name, 'settings.py'), 'w') as fd:
47+
fd.write(settingsfile.create(settings))
48+
49+
manage_file = 'manage.py'
50+
with open(manage_file, 'w') as fd:
51+
fd.write(gen_manage_py(name))
52+
53+
os.chmod(manage_file, 0o777)
54+
55+
56+
def validate_name(name):
57+
if not name:
58+
raise ValueError("Name cannot be empty")
59+
60+
# Can the name be used as an identifier in python (module or package name)
61+
if not name.isidentifier():
62+
raise ValueError(f"{name} is not a valid identifier")
63+
64+
65+
def gen_manage_py(project_name):
66+
lines = [
67+
'#!/usr/bin/env python3',
68+
'import os',
69+
'import sys',
70+
'',
71+
'if __name__ == "__main__":',
72+
' os.environ.setdefault("DEMOSYS_SETTINGS_MODULE", "{}.settings")'.format(project_name),
73+
'',
74+
' from demosys.core.management import execute_from_command_line',
75+
'',
76+
' execute_from_command_line(sys.argv)'
77+
]
78+
return "\n".join(lines)

demosys_test/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Entrypoint
2+
Entrypoint for custom entrypoint in setup.py
33
"""
44
import os
55
import sys

demosys_test/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"resizable": True,
2222
"fullscreen": False,
2323
"title": "demosys-py",
24-
"cursor": True,
24+
"cursor": False,
2525
}
2626

2727
MUSIC = os.path.join(PROJECT_DIR, 'resources/music/tg2035.mp3')

0 commit comments

Comments
 (0)