Skip to content

Commit

Permalink
* Better 'manager_frontend' structure, cleaning some minor things, close
Browse files Browse the repository at this point in the history
 recalbox#34;

* Added 'asset_tag';
* Dont show 'available systems' form if all systems allready exist, close recalbox#35;
* Moved 'Recalbox manifest' stuff into 'project.recalbox_manifest', removed manifest loading from settings in profit of loading from 'urls.py';
* Bump to 1.1.0;
  • Loading branch information
sveetch committed Oct 17, 2015
1 parent 40e2d69 commit af3f5f6
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 55 deletions.
10 changes: 9 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
History
=======

Version 1.1.0 - 2015/10/17
--------------------------

* Better 'manager_frontend' structure, cleaning some minor things, close #34;
* Added ``asset_tag``;
* Dont show 'available systems' form if all systems allready exist, close #35;
* Moved 'Recalbox manifest' stuff into ``project.recalbox_manifest``, removed manifest loading from settings in profit of loading from ``urls.py``;

Version 1.0.2 - 2015/10/16
--------------------------

* Fixed CRLF caracters when editing recalbox config, close #31;
* Fixed not packaged assets with production settings;
* Refactored asset management to use persistent manifest registry (avoid to load JSON manifest file on every request) and move it to its own embedded app to ``project.assets_cartographer``;
* Refactored asset management to use persistent manifest registry (avoid to load JSON manifest file on every request) and move it to its own embedded app to ``project.assets_cartographer``, close #33;
* Open Virtual gamepad link into a new window/tab;
* Fixed Dropzone assets, close #32;
* Moved Python requirements to ``pip-requirements`` directory and refactored them for backward compatible with Recalbox versions without ``psutil`` yet;
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Before doing anything, ensure the Raspberry can access to the internet else conf

Go where you want to install the manager directory then type the following commands: ::

wget -q -O - https://raw.githubusercontent.com/sveetch/recalbox-manager/master/deployment/install.sh | bash /dev/stdin --release=1.0.2
wget -q -O - https://raw.githubusercontent.com/sveetch/recalbox-manager/master/deployment/install.sh | bash /dev/stdin --release=1.1.0

This will download an install script and automatically execute it to proceed to install.

Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Django project to manage a Recalbox from a web interface
"""
__version__ = '1.0.2'
__version__ = '1.1.0'
2 changes: 1 addition & 1 deletion project/assets_cartographer/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
This would eventually not work with static files through S3/etc..
"""
import json, os
import os

from django.conf import settings
from django.template import Context
Expand Down
26 changes: 23 additions & 3 deletions project/assets_cartographer/templatetags/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
TODO: another tag for loading asset kind that are not stylesheet or javascript
"""
from django.template.defaulttags import register

from project.assets_cartographer import manifest
from project.assets_cartographer.parser import AssetTagsManagerFromManifest
from django.template.defaulttags import register

def render_asset_tags(kind, *bundle_names):
"""
Expand All @@ -18,6 +19,25 @@ def render_asset_tags(kind, *bundle_names):
return AssetTagsManagerFromManifest(manifest.get_registry()).render_for_kind(bundle_names, kind)


@register.simple_tag
def asset_tag(kind, *bundle_names):
"""
Build tag for any kind of asset
Usage
*****
Give asset kind name as first argument, then package names (one or more) as other arguments: ::
{% asset_tag "stylesheet" "css/item1.min.css" "css/item2.min.css" .. %}
Depending on settings.ASSETS_PACKAGED it would build an unique tag (if True) for the packaged asset file or tag (if False) for each package components files.
Obviously, the given kind have to exist in your asset manifest.
"""
return render_asset_tags(kind, *bundle_names)


@register.simple_tag
def stylesheet_tag(*bundle_names):
"""
Expand All @@ -26,7 +46,7 @@ def stylesheet_tag(*bundle_names):
Usage
*****
Just gives package names (one or more) as arguments: ::
Just give package names (one or more) as arguments: ::
{% stylesheet_tag "css/item1.min.css" "css/item2.min.css" .. %}
Expand All @@ -43,7 +63,7 @@ def javascript_tag(*bundle_names):
Usage
*****
Just gives package names (one or more) as arguments: ::
Just give package names (one or more) as arguments: ::
{% javascript_tag "css/item1.min.js" "css/item2.min.js" .. %}
Expand Down
10 changes: 7 additions & 3 deletions project/manager_frontend/forms/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
from django.utils.translation import ugettext_lazy as _
from django.core.files.storage import FileSystemStorage

from project.recalbox_manifest import manifest as RECALBOX_MANIFEST

from project.manager_frontend.forms import CrispyFormMixin

from project.utils.imports import safe_import_module

class SystemCreateForm(CrispyFormMixin, forms.Form):
#class SystemCreateForm(CrispyFormMixin, forms.Form):
class SystemCreateForm(forms.Form):
"""
Create a new system directory
"""
Expand All @@ -23,7 +27,7 @@ def __init__(self, *args, **kwargs):
self.available_systems = kwargs.pop('available_systems')

super(SystemCreateForm, self).__init__(*args, **kwargs)
super(forms.Form, self).__init__(*args, **kwargs)
#super(forms.Form, self).__init__(*args, **kwargs)

self.fields['name'] = forms.ChoiceField(label=_('Add a new system'), choices=self.available_systems, required=True)

Expand All @@ -32,4 +36,4 @@ def save(self):

os.mkdir(os.path.join(settings.RECALBOX_ROMS_PATH, name), 0755)

return settings.RECALBOX_MANIFEST[name]
return RECALBOX_MANIFEST[name]
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@
<li><span class="label info radius">{% trans "Total" %}: {{ systems_list|length }}</span></li>
</ul>

{% comment %}<div class="row systems-list">{% for key,name in systems_list %}
<div class="small-6 large-3 columns folder text-center{% if forloop.last %} end{% endif %}">
<a href="{% url 'manager:roms-list' system=key %}" class="button large expand radius">
<i class="icon-folder icon-4x"></i> {{ name }}
</a>
</div>
{% endfor %}</div>{% endcomment %}

<form action="." method="post">
{% if available_systems %}<form action="." method="post">
{% csrf_token %}
<div class="row">
<div class="large-12 columns">
Expand Down Expand Up @@ -47,7 +39,7 @@
</div>
</div>
</div>
</form>
</form>{% endif %}


<div class="flex-grid marged systems-list">{% for key,name in systems_list %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import xml.etree.cElementTree as ET

class ManifestParser(object):
class RecalboxManifestParser(object):
"""
Recalbox XML manifest parser
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"""
Some common class based views
TODO: Move this into 'manager_frontend' app
"""
import json

from django.views.generic.edit import TemplateResponseMixin, FormMixin, ProcessFormView
from django.http import HttpResponse

from project.manager_frontend.forms.roms import RomUploadForm, RomDeleteForm

class MultiFormView(TemplateResponseMixin, FormMixin, ProcessFormView):
"""
This is a huge rewrite and mixing of some CBV views and mixins to be able
Expand All @@ -29,9 +25,9 @@ class MultiFormView(TemplateResponseMixin, FormMixin, ProcessFormView):
Both must be unique through the forms of the view.
WARNING: This view should implement some warnings about needed stuff like
form attributes and form object names if not defined. So actually
you'll have to remember of this yourself.
TODO: This view should implement some warnings about needed stuff like
form attributes and form object names if not defined. So actually
you'll have to remember of this yourself.
"""
# The patterns used to find method/names from form 'form_key' attribute
getformkwargs_pattern = 'get_{}_form_kwargs'
Expand Down
10 changes: 5 additions & 5 deletions project/manager_frontend/views/bios.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""
Views for Bios views
"""
import os, re
import os
from operator import itemgetter

from django.conf import settings
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.http import Http404, HttpResponseBadRequest
from django.utils.translation import ugettext as _

from project.recalbox_manifest import manifest as RECALBOX_MANIFEST

from project.manager_frontend.forms.bios import BiosDeleteForm, BiosUploadForm
from project.utils.views import MultiFormView, JsonMixin
from project.manager_frontend.utils.views import MultiFormView, JsonMixin

class BiosListView(MultiFormView):
"""
Expand Down Expand Up @@ -49,7 +49,7 @@ def get_bios_manifest(self):
"""
bios_dict = {}

for system_key, system_datas in settings.RECALBOX_MANIFEST.items():
for system_key, system_datas in RECALBOX_MANIFEST.items():
system_name = system_datas.get('name', system_key)
if len(system_datas.get('bios', []))>0:
for md5hash,filename in system_datas['bios']:
Expand Down
2 changes: 0 additions & 2 deletions project/manager_frontend/views/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os

from django.conf import settings
from django.shortcuts import render
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
from django.core.urlresolvers import reverse
from django.contrib import messages
Expand Down
1 change: 0 additions & 1 deletion project/manager_frontend/views/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Views for logs files
"""
from django.conf import settings
from django.shortcuts import render
from django.views.generic import TemplateView

class LogsView(TemplateView):
Expand Down
1 change: 0 additions & 1 deletion project/manager_frontend/views/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Monitoring views
"""
from django.conf import settings
from django.shortcuts import render
from django.views.generic import TemplateView

# Compatibility support for Recalbox versions from 3.2.x to 3.3.x
Expand Down
9 changes: 5 additions & 4 deletions project/manager_frontend/views/roms.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
"""
Views for roms
"""
import json, os
import os
from operator import itemgetter

from django.conf import settings
from django.views.generic import TemplateView
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.http import Http404, HttpResponseBadRequest
from django.utils.translation import ugettext as _

from project.recalbox_manifest import manifest as RECALBOX_MANIFEST

from project.manager_frontend.forms.roms import RomUploadForm, RomDeleteForm
from project.utils.views import MultiFormView, JsonMixin
from project.manager_frontend.utils.views import MultiFormView, JsonMixin


class RomListView(MultiFormView):
Expand Down Expand Up @@ -42,7 +43,7 @@ def init_system(self):
'name': self.system_key
})
# Get the system manifest part if any, else a default dict
self.system_manifest = settings.RECALBOX_MANIFEST.get(self.system_key, default_manifest)
self.system_manifest = RECALBOX_MANIFEST.get(self.system_key, default_manifest)

def get_rom_choices(self):
rom_list = []
Expand Down
16 changes: 8 additions & 8 deletions project/manager_frontend/views/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.contrib import messages
from django.utils.translation import ugettext as _

from project.recalbox_manifest import manifest as RECALBOX_MANIFEST

from project.manager_frontend.forms.systems import SystemCreateForm

class SystemsListView(FormView):
Expand All @@ -29,14 +31,14 @@ def get_system_list(self):
# Only display directories
if os.path.isdir(os.path.join(path, item)) and not item.startswith('.'):
# Try to find the dirname in the system manifest
if item in settings.RECALBOX_MANIFEST:
existing_sys.append( (item, settings.RECALBOX_MANIFEST[item]['name']) )
if item in RECALBOX_MANIFEST:
existing_sys.append( (item, RECALBOX_MANIFEST[item]['name']) )
# Unknowed dirname
else:
existing_sys.append( (item, item) )

# Get system available: the ones that dont allready have a directory in systems dir
for sys_key, sys_values in settings.RECALBOX_MANIFEST.items():
for sys_key, sys_values in RECALBOX_MANIFEST.items():
if sys_key not in [v[0] for v in existing_sys]:
available_sys.append( (sys_key, sys_values['name']) )

Expand All @@ -50,6 +52,7 @@ def get_context_data(self, **kwargs):
context.update({
'systems_path': settings.RECALBOX_ROMS_PATH,
'systems_list': self.existing_systems,
'available_systems': self.available_systems,
})
return context

Expand All @@ -63,11 +66,8 @@ def get_form_kwargs(self):
def form_valid(self, form):
new_system = form.save()

## Throw a message to tell about upload success
#if is_backuped:
#messages.success(self.request, _('File has been backuped then edited'))
#else:
#messages.success(self.request, _('File has been edited'))
# Throw a message to tell about upload success
messages.success(self.request, _('System "{}" has been created').format(new_system['name']))

return super(SystemsListView, self).form_valid(form)

Expand Down
17 changes: 17 additions & 0 deletions project/recalbox_manifest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Recalbox manifest to know everything about supported systems
"""
import os, json
from .registry import manifest

def autodiscover():
"""
Dummy loader actually, this should be backward compatible for futur assets
discovery per app
"""
from django.conf import settings
from .parser import RecalboxManifestParser
# Fill the registry with the whole JSON manifest
manifest.update(
RecalboxManifestParser(settings.RECALBOX_MANIFEST_FILEPATH).read()
)
Loading

0 comments on commit af3f5f6

Please sign in to comment.