Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:mozilla/FlightDeck into bug-61532…
Browse files Browse the repository at this point in the history
…5-tree-ui
  • Loading branch information
seanmonstar committed Feb 9, 2011
2 parents aebc4d4 + d6eb467 commit 95376a4
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 18 deletions.
9 changes: 9 additions & 0 deletions apps/base/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from celery.decorators import task


@task(rate_limit='10/s')
def touch_a_file(filename):
f = open(filename,'w')
f.write('touched')
f.close();

45 changes: 45 additions & 0 deletions apps/base/templates/monitor.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,49 @@ <h2 class="UI_Heading" style="padding-top: 3em">Filepaths</h2>
{% endfor %}
</dl>

<h2 class="UI_Heading" style="padding-top: 3em">Free space</h2>
<ul>
{% for path, size in free.items %}
<li>{{ path }}: {{ size }}kB</li>
{% endfor %}
</ul>

<h2 class="UI_Heading" style="padding-top: 3em">Celery creates file</h2>
<p>{{ monitor_file }}</p>
<p id='monitor_file_result'>Waiting...</p>

<script type="text/javascript">
window.addEvent('load', function(){
(function(){
var monitor_file_result = $('monitor_file_result');
new Request.JSON({
url: '{% url monitor_file %}',
method: 'post',
data: {
'monitor_file': '{{ monitor_file }}'
},
onSuccess: function(result) {
if (!result.success) {
monitor_file_result.set('text', 'FAIL');
return;
}
new Request.JSON({
url: '{% url monitor_file %}',
method: 'post',
data: {
'monitor_file': '{{ monitor_file }}'
},
onSuccess: function(result) {
monitor_file_result.set('text',
(result.success)
? 'FAIL - file received but not deleted' : 'SUCCESS');
}
}).send();
}
}).send();
}).delay(1000);
});
</script>


{% endblock %}
1 change: 1 addition & 0 deletions apps/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
url('^robots.txt$', 'base.views.robots'),
url('^services/monitor$', 'base.views.monitor', name='monitor'),
url('^services/settings$', 'base.views.site_settings', name='settings'),
url('^services/monitor_file$', 'base.views.monitor_file_check', name='monitor_file'),
)
29 changes: 28 additions & 1 deletion apps/base/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os
import simplejson

import commonware.log
from django.conf import settings
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext, loader
from django.views.debug import get_safe_settings


from jetpack.models import Package, SDK
import base.tasks

log = commonware.log.getLogger('f.monitor')


@user_passes_test(lambda u: u.is_superuser)
Expand Down Expand Up @@ -48,6 +52,19 @@ def monitor(request):
status = False
filepath_results.append((path, path_exists, path_perms, notes))

# free space on XPI_TARGETDIR disk
x_path = '%s/' % settings.XPI_TARGETDIR
s_path = '%s/' % settings.SDKDIR_PREFIX
x = os.statvfs(x_path)
s = os.statvfs(s_path)
data['free'] = {
'xpi_targetdir %s' % x_path: (x.f_bavail * x.f_frsize) / 1024,
'sdkdir_prefix %s' % s_path: (s.f_bavail * s.f_frsize) / 1024
}
monitor_file = os.path.join(x_path, 'monitor.txt')
base.tasks.touch_a_file.delay(monitor_file)
data['monitor_file'] = monitor_file

data['filepaths'] = filepath_results
template = loader.get_template('monitor.html')
context = RequestContext(request, data)
Expand All @@ -56,6 +73,16 @@ def monitor(request):
return HttpResponse(template.render(context), status=status)


def monitor_file_check(request):
monitor_file = request.POST.get('monitor_file')
file_existed = False;
if os.path.isfile(monitor_file):
# delete file
os.remove(monitor_file)
# return JSON
file_existed = True
return HttpResponse(simplejson.dumps({"success": file_existed}))

def homepage(r):
# one more for the main one
addons_limit = settings.HOMEPAGE_PACKAGES_NUMBER
Expand Down
29 changes: 25 additions & 4 deletions apps/jetpack/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ def get_sdk_revision(self):

return self.sdk.kit_lib if self.sdk.kit_lib else self.sdk.core_lib

def build_xpi(self, modules=[], hashtag=None, rapid=False):
def build_xpi(self, modules=[], attachments=[], hashtag=None, rapid=False):
"""
prepare and build XPI for test only (unsaved modules)
Expand Down Expand Up @@ -1045,8 +1045,17 @@ def build_xpi(self, modules=[], hashtag=None, rapid=False):
e_mod.export_code(lib_dir)
if not mod_edited:
mod.export_code(lib_dir)
self.export_attachments(
'%s/%s' % (package_dir, self.package.get_data_dir()))
data_dir = os.path.join(package_dir, self.package.get_data_dir())
for att in self.attachments.all():
att_edited = False
for e_att in attachments:
if e_att.pk == att.pk:
att_edited = True
e_att.export_code(data_dir)
if not att_edited:
att.export_file(data_dir)
#self.export_attachments(
# '%s/%s' % (package_dir, self.package.get_data_dir()))
self.export_dependencies(packages_dir, sdk=self.sdk)

args = [sdk_dir, '%s/packages/%s' % (sdk_dir, self.package.name),
Expand Down Expand Up @@ -1167,7 +1176,9 @@ def save(self, *args, **kwargs):

def export_code(self, lib_dir):
" creates a file containing the module "
handle = open('%s/%s.js' % (lib_dir, self.filename), 'w')
path = os.path.join(lib_dir, '%s.js' % self.filename)
make_path(os.path.dirname(os.path.abspath(path)))
handle = open(path, 'w')
handle.write(self.code)
handle.close()

Expand Down Expand Up @@ -1274,6 +1285,16 @@ def write(self):
handle.write(data)
handle.close()

def export_code(self, static_dir):
" creates a file containing the module "
if not hasattr(self, 'code'):
return self.export_file(static_dir)
path = os.path.join(static_dir, '%s.%s' % (self.filename, self.ext))
make_path(os.path.dirname(os.path.abspath(path)))
handle = open(path, 'w')
handle.write(self.code)
handle.close()

def export_file(self, static_dir):
" copies from uploads to the package's data directory "
path = os.path.join(static_dir, '%s.%s' % (self.filename, self.ext))
Expand Down
6 changes: 6 additions & 0 deletions apps/jetpack/templates/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
</a>
</li>
{% endif %}
<li class="UI_Editor_Menu_Button Icon_logs">
<a id="error-console" title="" href="#">
Error Console
<span class="UI_Editor_Icon"></span>
</a>
</li>
{% include "_editor_app_menu_items.html" %}
</ul>
</div> <!-- /editor-menu-wrapper -->
Expand Down
9 changes: 8 additions & 1 deletion apps/xpi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ def prepare_test(r, id_number, revision_number=None):
if mod.code != code:
mod.code = code
modules.append(mod)
response, rm_xpi_url = revision.build_xpi(modules, hashtag=hashtag)
attachments = []
for att in revision.attachments.all():
if r.POST.get(str(att.pk), False):
code = r.POST.get(str(att.pk))
att.code = code
attachments.append(att)
response, rm_xpi_url = revision.build_xpi(modules, attachments,
hashtag=hashtag)
else:
response, rm_xpi_url = revision.build_xpi(hashtag=hashtag)
return HttpResponse('{"delayed": true, "rm_xpi_url": "%s"}' % rm_xpi_url)
Expand Down
5 changes: 5 additions & 0 deletions media/jetpack/css/UI.Editor_Menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@ authors:
.UI_Editor_Menu_Button.Icon_copy a .UI_Editor_Icon {
background-position: -161px 0;
}

.UI_Editor_Menu_Button.Icon_logs a .UI_Editor_Icon {
background-position: -178px 0;
}

Binary file modified media/jetpack/img/editor-buttons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions media/jetpack/js/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var Package = new Class({
copy_el: 'package-copy',
test_el: 'try_in_browser',
download_el: 'download',
console_el: 'error-console',
check_if_latest: true // switch to false if displaying revisions
},

Expand Down Expand Up @@ -66,7 +67,13 @@ var Package = new Class({
if (this.isAddon()) {
this.boundTestAddon = this.testAddon.bind(this);
this.options.test_url = $(this.options.test_el).get('href');
$(this.options.test_el).addEvent('click', this.boundTestAddon)
$(this.options.test_el).addEvent('click', this.boundTestAddon);
this.boundDownloadAddon = this.downloadAddon.bind(this);
this.download_url = $(this.options.download_el).get('href');
$(this.options.download_el).addEvent('click', this.boundDownloadAddon);
$(this.options.console_el).addEvent('click', function(){
window.mozFlightDeck.send({ cmd: 'toggleConsole', contents: 'open' });
});
}
this.copy_el = $(this.options.copy_el)
if (this.copy_el) {
Expand Down Expand Up @@ -133,6 +140,7 @@ var Package = new Class({
hashtag: this.options.hashtag,
filename: this.options.name
};
$log(data);
new Request.JSON({
url: this.download_url,
data: data,
Expand Down Expand Up @@ -582,7 +590,7 @@ Package.View = new Class({
Package.Edit = new Class({

Extends: Package,

options: {
// DOM elements
save_el: 'package-save',
Expand Down Expand Up @@ -1079,9 +1087,8 @@ Package.Edit = new Class({

bind_keyboard: function() {
this.keyboard = new Keyboard({
defaultEventType: 'keyup',
events: {
'ctrl+s': this.boundSaveAction
'ctrl+s': this.boundSaveAction
}
});
this.keyboard.activate();
Expand Down
3 changes: 3 additions & 0 deletions migrations/001-readme.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This is a placeholder file:

-- This directory is for use with schematic. See https://github.com/jbalogh/schematic for help
29 changes: 29 additions & 0 deletions migrations/schematic_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import manage
from django.conf import settings

config = settings.DATABASES['default']
config['HOST'] = config.get('HOST', 'localhost')
config['PORT'] = config.get('PORT', '3306')

if not config['HOST'] or config['HOST'].endswith('.sock'):
""" Oh you meant 'localhost'! """
config['HOST'] = 'localhost'

s = 'mysql --silent {NAME} -h{HOST} -u{USER}'

if config['PASSWORD']:
s += ' -p{PASSWORD}'
else:
del config['PASSWORD']
if config['PORT']:
s += ' -P{PORT}'
else:
del config['PORT']

db = s.format(**config)
table = 'schema_version'
15 changes: 9 additions & 6 deletions scripts/crontab/make-crons.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
CRONS = {}

COMMON = {
'MANAGE': '/data/amo_python/src/builder.preview/flightdeck manage.py',
'MANAGE': '/usr/bin/python26 manage.py',
'F_CRON': '$DJANGO cron',
}

CRONS['prod'] = {
'FLIGHTDECK': '/data/amo_python/src/builder/flightdeck',
'DJANGO': 'apache cd $FLIGHTDECK; $MANAGE',
}

CRONS['preview'] = {
'FLIGHTDECK': '/data/amo_python/src/builder.preview/flightdeck',
'DJANGO': 'cd $FLIGHTDECK; $MANAGE',
}

CRONS['prod'] = {
'FLIGHTDECK': '/data/amo_python/src/builder/flightdeck',
'DJANGO': 'apache cd $FLIGHTDECK; $MANAGE',
}

Expand All @@ -40,9 +40,12 @@
#
# !!AUTO-GENERATED!! Edit scripts/crontab/make-crons.py instead.
#
MAILTO=flightdeck-developers@mozilla.org
#once per day
30 1 * * * $F_CRON clean_tmp
MAILTO=root
"""


Expand Down
5 changes: 4 additions & 1 deletion scripts/crontab/preview
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# !!AUTO-GENERATED!! Edit scripts/crontab/make-crons.py instead.
#
MAILTO=flightdeck-developers@mozilla.org

#once per day
30 1 * * * apache cd /data/amo_python/src/builder.preview/flightdeck; /data/amo_python/src/builder.preview/flightdeck manage.py cron clean_tmp
30 1 * * * cd /data/amo_python/src/builder.preview/flightdeck; /usr/bin/python26 manage.py cron clean_tmp

MAILTO=root
5 changes: 4 additions & 1 deletion scripts/crontab/prod
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# !!AUTO-GENERATED!! Edit scripts/crontab/make-crons.py instead.
#
MAILTO=flightdeck-developers@mozilla.org

#once per day
30 1 * * * apache cd /data/amo_python/src/builder/flightdeck; /data/amo_python/src/builder.preview/flightdeck manage.py cron clean_tmp
30 1 * * * apache cd /data/amo_python/src/builder/flightdeck; /usr/bin/python26 manage.py cron clean_tmp

MAILTO=root

0 comments on commit 95376a4

Please sign in to comment.