Commit d028712b authored by Alexandre Leray's avatar Alexandre Leray
Browse files

Some cleaning

parent e986c35c
......@@ -14,6 +14,7 @@ REST API
from django.conf.urls.defaults import url
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from tastypie import fields
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
......@@ -25,8 +26,8 @@ from tastypie.utils import trailing_slash
import time
from aawiki.mdx import get_markdown
from aawiki.mdx.mdx_sectionedit import (sectionalize, sectionalize_replace)
from aawiki.utils import convert_line_endings
from aawiki.utils.sections import (sectionalize, sectionalize_replace)
from aawiki.utils.sections import convert_line_endings
from aawiki.settings import REPO_PATH
from pygit2 import GIT_OBJ_BLOB, Repository, Signature
......@@ -40,6 +41,7 @@ from markdown.util import etree
REPO = Repository(REPO_PATH)
def assign_attrs(elem, attrs):
""" Assign attrs to element. """
for k, v in get_attrs(attrs):
......@@ -54,6 +56,7 @@ def assign_attrs(elem, attrs):
# assing attr k with v
elem.set(k, v)
def add_attributes_key (x):
if not x["index"] == 0:
RE = AttrListTreeprocessor.HEADER_RE
......@@ -81,7 +84,7 @@ class Section(object):
class PageManager(object):
def get(self, key, hex=None):
commit = REPO[hex] if hex else REPO.head
commit = REPO[hex] if hex else REPO[REPO.head.oid]
te = commit.tree[key]
blob = te.to_object()
content = blob.data.decode("utf-8")
......
......@@ -17,8 +17,8 @@
import re
from aawiki.mdx.mdx_sectionedit import (DATETIMECODE_HEADER_RE, spliterator)
from aawiki.timecode import (timecode_fromsecs, timecode_tosecs)
from utils.sections import (DATETIMECODE_HEADER_RE, spliterator)
from timecode import (timecode_fromsecs, timecode_tosecs)
def audacity_to_srt(data, explicit=False):
......@@ -26,44 +26,33 @@ def audacity_to_srt(data, explicit=False):
>>> data = '''90,610022 90,610022 first section
... 345,271874 345,271874 second section'''
>>> print(audacity_to_srt(data).strip())
00:01:30.610 -->
00:01:30,610 -->
<BLANKLINE>
first section
<BLANKLINE>
00:05:45.272 -->
00:05:45,272 -->
<BLANKLINE>
second section
>>> data = '''90,610022 345,271874 first section
... 345,271874 512,573912 second section'''
>>> print(audacity_to_srt(data).strip())
00:01:30.610 -->
00:01:30,610 -->
<BLANKLINE>
first section
<BLANKLINE>
00:05:45.272 --> 00:08:32.574
00:05:45,272 --> 00:08:32,574
<BLANKLINE>
second section
>>> data = '''90,610022 345,271874 first section
... 345,271874 512,573912 second section'''
>>> print(audacity_to_srt(data, explicit=True).strip())
00:01:30.610 --> 00:05:45.272
00:01:30,610 --> 00:05:45,272
<BLANKLINE>
first section
<BLANKLINE>
00:05:45.272 --> 00:08:32.574
<BLANKLINE>
second section
>>> data = '''90,610022 345,271874 first section
... 345,271874 512,573912'''
>>> print(audacity_to_srt(data).strip())
00:01:30.610 --> 00:05:45.272
<BLANKLINE>
first section
<BLANKLINE>
00:05:45.272 --> 00:08:32.574
00:05:45,272 --> 00:08:32,574
<BLANKLINE>
second section
"""
......@@ -84,10 +73,8 @@ def audacity_to_srt(data, explicit=False):
start = float(start.replace(',', '.'))
end = float(end.replace(',', '.'))
start = timecode_fromsecs(start, alwaysfract=True,
alwayshours=True, fractdelim=',')
end = timecode_fromsecs(end, alwaysfract=True,
alwayshours=True, fractdelim=',')
start = timecode_fromsecs(start, alwaysfract=True, alwayshours=True, fractdelim=',')
end = timecode_fromsecs(end, alwaysfract=True, alwayshours=True, fractdelim=',')
# If the end time equals the start time we ommit it.
if end == start:
......@@ -107,7 +94,51 @@ def audacity_to_srt(data, explicit=False):
def srt_to_audacity(data, force_endtime=False):
"""docstring for srt_to_audacity"""
"""
>>> data = '''00:01:30,610 -->
... <BLANKLINE>
... first section
... <BLANKLINE>
... 00:05:45,272 -->
... <BLANKLINE>
... second section'''
>>> print(srt_to_audacity(data).strip())
90,610022 90,610022 first section
345,271874 345,271874 second section
>>> data = '''00:01:30,610 -->
... <BLANKLINE>
... first section
... <BLANKLINE>
... 00:05:45,272 --> 00:08:32,574
... <BLANKLINE>
... second section'''
>>> print(srt_to_audacity(data).strip())
90,610022 345,271874 first section
345,271874 512,573912 second section
>>> data = '''00:01:30,610 --> 00:05:45,272
... <BLANKLINE>
... first section
... <BLANKLINE>
... 00:05:45,272 --> 00:08:32,574
... <BLANKLINE>
... second section'''
>>> print(srt_to_audacity(data, explicit=True).strip())
90,610022 345,271874 first section
345,271874 512,573912 second section
>>> data = '''00:01:30,610 --> 00:05:45,272
... <BLANKLINE>
... first section
... <BLANKLINE>
... 00:05:45,272 --> 00:08:32,574
... <BLANKLINE>
... second section'''
>>> print(srt_to_audacity(data).strip())
90,610022 345,271874 first section
345,271874 512,573912
"""
# FIXME: UnicodeDecodeError...
pattern = re.compile(DATETIMECODE_HEADER_RE, re.I | re.M | re.X)
......@@ -135,8 +166,3 @@ def srt_to_audacity(data, force_endtime=False):
if __name__ == "__main__":
import doctest
doctest.testmod()
f = open('/tmp/bla.srt', 'r')
data = f.read()
f.close()
#print(audacity_to_srt(data))
print(srt_to_audacity(data))
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from rdfutils import *
from aawiki.utils import (full_site_url, pagename_for_url)
from aawiki.utils.urls import (full_site_url, pagename_for_url)
from aawiki.models import Page
from aacore import RDF_MODEL
......
......@@ -16,7 +16,7 @@ try: from markdown.util import etree
except ImportError: from markdown import etree
import mdx_timecodes
from aawiki.utils import url_for_pagename
from aawiki.utils.urls import url_for_pagename
import urlparse
......
......@@ -13,17 +13,16 @@
this.element = element;
this.$element = $(element);
this.paused = true;
this.duration = opts.duration;
this.currentTime = 0;
this.loop = opts.loop;
/* Void player is always ready ! */
this.readyState = 4;
this.readyState = 4; // Void player is always ready !
this.seeking = false;
this.interval_id = undefined;
// console.log("duration", this.duration);
}
VoidPlayer.plugins = {};
......@@ -33,9 +32,7 @@
}
VoidPlayer.prototype.play = function () {
// console.log("voidplayer.play");
if (!this.interval_id) {
// console.log("VoidPlayer.play setInterval,", this.interval_id);
this.paused = false;
var that = this;
this.start = new Date().getTime() - (this.currentTime * 1000);
......@@ -57,7 +54,6 @@
VoidPlayer.prototype.pause = function () {
if (this.interval_id) {
// console.log("VoidPlayer.pause");
this.paused = true;
window.clearInterval(this.interval_id)
this.interval_id = null;
......@@ -99,97 +95,3 @@
}
})(jQuery);
//// jQuery.media timecode funcs
/**
* function String.toSeconds ()
*
* Convert any number to seconds
*/
//String.prototype.toSeconds = function () {
//var time = this;
//if (/^([0-9]{1,2}:)?[0-9]{1,2}:[0-9]{1,2}(\.[0-9]+)?(,[0-9]+)?$/.test(time)) {
//time = time.split(':', 3);
//if (time.length == 3) {
//var ms = time[2].split(',', 2);
//ms[1] = ms[1] ? ms[1] : 0;
//return ((((parseInt(time[0], 10) * 3600) + (parseInt(time[1], 10) * 60) + parseFloat(ms[0])) * 1000) + parseInt(ms[1], 10)) / 1000;
//}
//var ms = time[1].split(',', 1);
//ms[1] = ms[1] ? ms[1] : 0;
//return ((((parseInt(time[0], 10) * 60) + parseFloat(ms[0])) * 1000) + parseInt(ms[1], 10)) / 1000;
//}
//return parseFloat(time).toSeconds();
//}
/**
* function String.secondsTo (outputFormat)
*
* Convert a seconds time value to any other time format
*/
//String.prototype.secondsTo = function (outputFormat) {
//return this.toSeconds().secondsTo(outputFormat);
//}
/**
* function Number.toSeconds ()
*
* Convert any number to seconds
*/
//Number.prototype.toSeconds = function () {
//return Math.round(this * 1000) / 1000;
//}
/**
* function Number.secondsTo (outputFormat)
*
* Convert a seconds time value to any other time format
*/
//Number.prototype.secondsTo = function (outputFormat) {
//var time = this;
//switch (outputFormat) {
//case 'ms':
//return Math.round(time * 1000);
//case 'mm:ss':
//case 'hh:mm:ss':
//case 'hh:mm:ss.ms':
//var hh = '';
//if (outputFormat != 'mm:ss') {
//hh = Math.floor(time / 3600);
//time = time - (hh * 3600);
//hh = (hh < 10) ? ("0" + hh) : hh; // forces two digits hours
//hh += ':';
//}
//var mm = Math.floor(time / 60);
//time = time - (mm * 60);
//mm = (mm < 10) ? ("0" + mm) : mm;
//mm += ':';
//var ss = time;
//if (outputFormat == 'hh:mm:ss' || outputFormat == 'mm:ss') { // MLM: added mm:ss
//ss = Math.round(ss);
//}
//ss = (ss < 10) ? ("0" + ss) : ss;
//return hh + mm + ss;
//}
//return time;
//};
......@@ -64,13 +64,6 @@ class AATag(object):
self.output = self.run()
class AASparql(AATag):
name = "sparql"
def run(self):
return "ok"
class AAPageList(AATag):
name = "pagelist"
......@@ -109,7 +102,6 @@ class AAAuthors(AATag):
name = "authors"
def run(self):
print self.args
ret = query("""
SELECT DISTINCT ?object ?subject WHERE {
?object <http://activearchives.org/terms/author> ?subject .
......@@ -122,6 +114,18 @@ class AAAuthors(AATag):
return "".join(foo)
class AAAll(AATag):
name = "all"
def run(self):
results = query("SELECT DISTINCT ?o ?p ?s WHERE { ?o ?p ?s }", RDF_MODEL)
ret = ["<table>"]
for r in results:
ret.append(u"<tr><td>%s</td><td>%s</td><td>%s</td></tr>" % (r['o'], r['p'], r['s']))
ret.append("</table>")
return "".join(ret)
if __name__ == "__main__":
import doctest
doctest.testmod()
{% extends "aawiki/base.html" %}
{% load aacoretags aawikitags %}
{% load aacore_tags aawikitags %}
{% block title %}{{ block.super }} | {{ page.name }}{% endblock %}
......
{% extends "aawiki/base.html" %}
{% load aacoretags aawikitags %}
{% load aacore_tags aawikitags %}
{% block extrahead %}
<script>
......
......@@ -27,48 +27,48 @@
{% block body %}
{% get_markdown_for content as md meta %}
<a href="#t=300,600">00:05:00 --> 00:06:00</a>
<a href="#t=600,">00:06:00 --></a>
<span class="swatch" title="Drag over a section to apply the style">
<label for="font-size"><i class="icon-beaker"></i> font-size</label>
<select id="font-size">
<option value="">reset</option>
<option value="xx-small">xx-small</option>
<option value="x-small">x-small</option>
<option value="small">small</option>
<option value="medium">medium</option>
<option value="large">large</option>
<option value="x-large">x-large</option>
<option value="xx-large">xx-large</option>
<option value="smaller">smaller</option>
<option value="larger">larger</option>
</select>
</span>
<div id="toc">
<form>
<input name="foo" value="your_value" id="foo" type="checkbox">
<label for="foo"><i class="icon-eye-open"></i> name</label>
</form>
<style type="text/css" media="screen">
input[type="checkbox"] { display: none }
input[type="checkbox"] + label:before { content: "☆ " }
input[type="checkbox"]:checked + label:before { content: "★ " }
</style>
</div>
<div id="timelineslider"></div>
<form id="mode">
<input type="radio" id="modecanvas" name="mode" value="canvas">
<label for="modecanvas">canvas</label>
<input type="radio" id="modecinematic" name="mode" value="cinematic">
<label for="modecinematic">cinematic</label>
</form>
<!--<a href="#t=300,600">00:05:00 --&gt; 00:06:00</a>-->
<!--<a href="#t=600,">00:06:00 --&gt;</a>-->
<!--<span class="swatch" title="Drag over a section to apply the style">-->
<!--<label for="font-size"><i class="icon-beaker"></i> font-size</label> -->
<!--<select id="font-size">-->
<!--<option value="">reset</option>-->
<!--<option value="xx-small">xx-small</option>-->
<!--<option value="x-small">x-small</option>-->
<!--<option value="small">small</option>-->
<!--<option value="medium">medium</option>-->
<!--<option value="large">large</option>-->
<!--<option value="x-large">x-large</option>-->
<!--<option value="xx-large">xx-large</option>-->
<!--<option value="smaller">smaller</option>-->
<!--<option value="larger">larger</option>-->
<!--</select>-->
<!--</span>-->
<!--<div id="toc">-->
<!--<form>-->
<!--<input name="foo" value="your_value" id="foo" type="checkbox">-->
<!--<label for="foo"><i class="icon-eye-open"></i> name</label>-->
<!--</form>-->
<!--<style type="text/css" media="screen">-->
<!--input[type="checkbox"] { display: none }-->
<!--input[type="checkbox"] + label:before { content: "☆ " }-->
<!--input[type="checkbox"]:checked + label:before { content: "★ " }-->
<!--</style>-->
<!--</div>-->
<!--<div id="timelineslider"></div>-->
<!--<form id="mode">-->
<!--<input type="radio" id="modecanvas" name="mode" value="canvas">-->
<!--<label for="modecanvas">canvas</label>-->
<!--<input type="radio" id="modecinematic" name="mode" value="cinematic">-->
<!--<label for="modecinematic">cinematic</label>-->
<!--</form>-->
{{ md|render_aatags|safe }}
{% endblock %}
......
{% extends "aawiki/base.html" %}
{% load aacoretags aawikitags %}
{% load aacore_tags aawikitags %}
{% block title %}{% get_markdown_for content as md meta %}{{ block.super }} | Comparing {{ slug }} as edited by {{ c1.author.name }} at {{ c1.commit_time|fromtimestamp }} and as edited by {{ c2.author.name }} at {{ c2.commit_time|fromtimestamp }}{% endblock %}
......
{% extends "aawiki/base.html" %}
{% load aacoretags aawikitags %}
{% load aacore_tags aawikitags %}
......
{% load aacoretags aawikitags %}
{% load aacore_tags aawikitags %}
{% get_markdown_for content as md meta %}
......
{% extends "aawiki/base.html" %}
{% load aacoretags aawikitags %}
{% load aacore_tags aawikitags %}
{% block title %}{{ block.super }}Register for an account{% endblock %}
......
......@@ -38,7 +38,7 @@ def wikify(value):
"""
Wikifies the given string
"""
return utils.wikify(value)
return utils.urls.wikify(value)
@register.filter
......
......@@ -4,8 +4,6 @@
"""
Splits a markdown source into a flat list of sections.
Markdown extension adds {@data-section=%d} attribute markup to headers.
Provides: sectionalize
>>> txt = '''
......@@ -80,7 +78,6 @@ Provides: sectionalize
"""
import markdown
import re
......@@ -293,39 +290,17 @@ def sectionalize_replace (original_text, section_number, new_text):
return u"".join([pre_text, new_text, post_text])
class SectionEditExtension(markdown.Extension):
def __init__(self, configs={}):
self.config = {}
for key, value in configs:
self.setConfig(key, value)
def extendMarkdown(self, md, md_globals):
""" Add SectionEditPreprocessor to the Markdown instance. """
ext = SectionEditPreprocessor(md)
ext.config = self.config
md.preprocessors.add('section_edit_block', ext, ">timecodes_block")
class SectionEditPreprocessor(markdown.preprocessors.Preprocessor):
def run(self, lines):
""" Adds section numbers to sections """
newlines = []
pattern = re.compile(HASH_OR_DATETIMECODE_HEADER_RE % '1,6', re.M)
i = 0
for line in lines:
if pattern.match(line):
i += 1
newlines.append(line.rstrip() + " {@data-section=%d}" % i)
else:
newlines.append(line)
return newlines
def makeExtension(configs={}):
return SectionEditExtension(configs=configs)
def convert_line_endings(temp, mode):
#modes: 0 - Unix, 1 - Mac, 2 - DOS
if mode == 0:
temp = string.replace(temp, '\r\n', '\n')
temp = string.replace(temp, '\r', '\n')
elif mode == 1:
temp = string.replace(temp, '\r\n', '\r')
temp = string.replace(temp, '\n', '\r')
elif mode == 2:
temp = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", temp)
return temp
if __name__ == "__main__":
......
#https://github.com/louissobel/srt.py/blob/master/srt.py
#https://github.com/riobard/srt.py
def tc2ms(tc):
'''
converts timecode to millisecond
'''
sign = 1
if tc[0] in "+-":
sign = -1 if tc[0] == "-" else 1
tc = tc[1:]
TIMECODE_RE = re.compile('(?:(?:(?:(\d?\d):)?(\d?\d):)?(\d?\d))?(?:[,.](\d?\d?\d))?')
# NOTE the above regex matches all following cases
# 12:34:56,789
# 01:02:03,004
# 1:2:3,4 => 01:02:03,004
# ,4 => 00:00:00,004
# 3 => 00:00:03,000
# 3,4 => 00:00:03,004
# 1:2 => 00:01:02,000
# 1:2,3 => 00:01:03,003
# 1:2:3 => 01:02:03
# also accept "." instead of "," as millsecond separator
match = TIMECODE_RE.match(tc)
try:
assert match is not None
except AssertionError:
print tc
hh,mm,ss,ms = map(lambda x: 0 if x==None else in