Merge branch 'py3'
This commit is contained in:
commit
5cd55d15bd
11 changed files with 52 additions and 48 deletions
|
@ -47,3 +47,8 @@ The encoding part is delegated to `ffmpeg`, but the code is really modular so
|
|||
changing this is a breeze. To be quicker and avoid the quality issues related
|
||||
to reencoding, the codec "copy" is used: this means that input and output must
|
||||
have the same format.
|
||||
|
||||
testing
|
||||
-----------
|
||||
|
||||
unit tests can be run with `python setup.py test`
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
import server
|
||||
import cli
|
||||
from . import server
|
||||
from . import cli
|
||||
|
|
|
@ -9,10 +9,10 @@ logger = logging.getLogger('cli')
|
|||
|
||||
CWD = os.getcwd()
|
||||
|
||||
import forge
|
||||
import maint
|
||||
from config_manager import get_config
|
||||
import server
|
||||
from . import forge
|
||||
from . import maint
|
||||
from .config_manager import get_config
|
||||
from . import server
|
||||
|
||||
|
||||
def pre_check_permissions():
|
||||
|
@ -84,6 +84,7 @@ def common_pre():
|
|||
def main():
|
||||
parser = ArgumentParser(description='creates mp3 from live recordings')
|
||||
parser.add_argument('--verbose', '-v', action='count',
|
||||
default=0,
|
||||
help='Increase verbosity; can be used multiple times')
|
||||
parser.add_argument('--pretend', '-p', action='store_true', default=False,
|
||||
help='Only pretend; no real action will be done')
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
'''
|
||||
This module contains DB logic
|
||||
'''
|
||||
from __future__ import print_function
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
@ -11,7 +12,7 @@ from sqlalchemy import create_engine, Column, Integer, String, DateTime, inspect
|
|||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
from config_manager import get_config
|
||||
from .config_manager import get_config
|
||||
|
||||
PAGESIZE = 10
|
||||
|
||||
|
@ -218,7 +219,7 @@ class RecDB:
|
|||
return ret
|
||||
|
||||
def get_err(self):
|
||||
print "DB error: %s" % (self.err)
|
||||
print("DB error: %s" % (self.err))
|
||||
t = self.err
|
||||
self.err = ""
|
||||
return t
|
||||
|
@ -227,25 +228,25 @@ class RecDB:
|
|||
if __name__ == "__main__":
|
||||
def printall(queryres):
|
||||
for record in queryres:
|
||||
print "Record: %s" % record
|
||||
print("Record: %s" % record)
|
||||
|
||||
db = RecDB()
|
||||
_mytime = datetime(2014, 05, 23, 15, 12, 17)
|
||||
_endtime = datetime(2014, 05, 24, 17, 45, 17)
|
||||
_mytime = datetime(2014, 5, 23, 15, 12, 17)
|
||||
_endtime = datetime(2014, 5, 24, 17, 45, 17)
|
||||
|
||||
a = Rec(name="Mimmo1", starttime=_mytime, endtime=_endtime)
|
||||
printall(db._search())
|
||||
sys.exit("End test job")
|
||||
|
||||
# a = Rec(name="Mimmo1", starttime=_mytime, endtime=None)
|
||||
print "Aggiunto", db.add(a)
|
||||
print("Aggiunto", db.add(a))
|
||||
printall(db.get_all(page_size=5, page=0))
|
||||
|
||||
print "Mimmo "
|
||||
print("Mimmo ")
|
||||
printall(db._search(name="Mimmo1"))
|
||||
print "Search"
|
||||
print("Search")
|
||||
printall(db._search(name="Mimmo1",
|
||||
starttime=datetime(2014, 05, 24, 15, 16, 1) ))
|
||||
starttime=datetime(2014, 5, 24, 15, 16, 1) ))
|
||||
a = db.get_by_id(5)
|
||||
a.start()
|
||||
db.delete(1)
|
|
@ -33,7 +33,5 @@ try:
|
|||
if resource_isdir('techrec', 'pages'):
|
||||
STATIC_PAGES = resource_filename('techrec', 'pages')
|
||||
STATIC_FILES = resource_filename('techrec', 'static')
|
||||
else:
|
||||
print "invece dice", resource_filename('techrec', 'static')
|
||||
except ImportError:
|
||||
logging.exception("Error loading resources from installed part")
|
||||
|
|
|
@ -4,7 +4,7 @@ import os
|
|||
from subprocess import Popen
|
||||
import logging
|
||||
|
||||
from config_manager import get_config
|
||||
from .config_manager import get_config
|
||||
|
||||
|
||||
def get_timefile_exact(time):
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import print_function
|
||||
import sys
|
||||
import logging
|
||||
|
||||
from sqlalchemy import inspect
|
||||
|
||||
from config_manager import get_config
|
||||
from techrec import RecDB
|
||||
from .config_manager import get_config
|
||||
from .db import RecDB
|
||||
|
||||
def cleanold_cmd(options):
|
||||
log = logging.getLogger('cleanold')
|
||||
|
@ -14,7 +15,7 @@ def cleanold_cmd(options):
|
|||
count = len(res)
|
||||
if options.pretend:
|
||||
for rec in res:
|
||||
print rec
|
||||
print(rec)
|
||||
else:
|
||||
for rec in res:
|
||||
logging.info("Deleting " + str(rec))
|
||||
|
|
|
@ -40,11 +40,11 @@ class JobQueue(object):
|
|||
|
||||
def simulate_long_job(recid=None, starttime=None, endtime=None, name='', filename=None):
|
||||
from time import sleep
|
||||
print "evviva " + name
|
||||
print("evviva " + name)
|
||||
sleep(2)
|
||||
print "lavoro su " + name
|
||||
print("lavoro su " + name)
|
||||
sleep(2)
|
||||
print "done su " + name
|
||||
print("done su " + name)
|
||||
_queue = None
|
||||
|
||||
|
||||
|
@ -60,15 +60,15 @@ if __name__ == '__main__':
|
|||
|
||||
def sleep(n):
|
||||
import time
|
||||
print "Inizio %d" % n
|
||||
print("Inizio %d" % n)
|
||||
time.sleep(n)
|
||||
print "Finisco %d" % n
|
||||
print("Finisco %d" % n)
|
||||
return n
|
||||
|
||||
get_process_queue().submit(sleep, 3)
|
||||
get_process_queue().submit(sleep, 3)
|
||||
get_process_queue().join()
|
||||
print get_process_queue().jobs
|
||||
print(get_process_queue().jobs)
|
||||
delta = (datetime.now() - n).total_seconds()
|
||||
print delta
|
||||
print(delta)
|
||||
assert 5 < delta < 7
|
||||
|
|
|
@ -14,10 +14,10 @@ botlog.setLevel(logging.INFO)
|
|||
botlog.addHandler(logging.StreamHandler(sys.stdout))
|
||||
bottle._stderr = lambda x: botlog.info(x.strip())
|
||||
|
||||
from techrec import Rec, RecDB
|
||||
from processqueue import get_process_queue
|
||||
from forge import create_mp3
|
||||
from config_manager import get_config
|
||||
from .db import Rec, RecDB
|
||||
from .processqueue import get_process_queue
|
||||
from .forge import create_mp3
|
||||
from .config_manager import get_config
|
||||
|
||||
|
||||
def date_read(s):
|
||||
|
@ -89,13 +89,13 @@ class RecAPI(Bottle):
|
|||
self.get('/jobs/<job_id:int>', callback=self.check_job)
|
||||
|
||||
def create(self):
|
||||
req = dict(request.POST.allitems())
|
||||
req = dict(request.POST.decode().allitems())
|
||||
ret = {}
|
||||
logger.debug("Create request %s " % req)
|
||||
|
||||
now = datetime.now()
|
||||
start = date_read(req['starttime']) if 'starttime' in req else now
|
||||
name = req['name'].decode('utf8') if 'name' in req else u""
|
||||
name = req['name'] if 'name' in req else u""
|
||||
end = date_read(req['endtime']) if 'endtime' in req else now
|
||||
|
||||
rec = Rec(name=name,
|
||||
|
@ -107,7 +107,7 @@ class RecAPI(Bottle):
|
|||
rec=rec_sanitize(rec))
|
||||
|
||||
def delete(self):
|
||||
req = dict(request.POST.allitems())
|
||||
req = dict(request.POST.decode().allitems())
|
||||
logging.info("Server: request delete %s " % (req))
|
||||
if 'id' not in req:
|
||||
return self.rec_err("No valid ID")
|
||||
|
@ -118,7 +118,7 @@ class RecAPI(Bottle):
|
|||
return self.rec_err("DELETE error: %s" % (self.db.get_err()))
|
||||
|
||||
def update(self, recid):
|
||||
req = dict(request.POST.allitems())
|
||||
req = dict(request.POST.decode().allitems())
|
||||
|
||||
newrec = {}
|
||||
now = datetime.now()
|
||||
|
@ -131,7 +131,7 @@ class RecAPI(Bottle):
|
|||
else:
|
||||
newrec['endtime'] = date_read(req['endtime'])
|
||||
if 'name' in req:
|
||||
newrec["name"] = req['name'].decode('utf8')
|
||||
newrec["name"] = req['name']
|
||||
|
||||
try:
|
||||
logger.info("prima di update")
|
||||
|
@ -144,7 +144,7 @@ class RecAPI(Bottle):
|
|||
|
||||
def generate(self):
|
||||
# prendiamo la rec in causa
|
||||
recid = dict(request.POST.allitems())['id']
|
||||
recid = dict(request.POST.decode().allitems())['id']
|
||||
rec = self.db._search(_id=recid)[0]
|
||||
if rec.filename is not None and os.path.exists(rec.filename):
|
||||
return {'status': 'ready',
|
||||
|
@ -166,8 +166,8 @@ class RecAPI(Bottle):
|
|||
'endtime': rec.endtime.strftime('%H%M'),
|
||||
'startdt': rec.starttime.strftime('%y%m%d_%H%M'),
|
||||
'enddt': rec.endtime.strftime('%y%m%d_%H%M'),
|
||||
'name': filter(lambda c: c.isalpha(),
|
||||
unicodedata.normalize('NFKD', rec.name).encode('ascii', 'ignore')),
|
||||
'name': ''.join(filter(lambda c: c.isalpha(),
|
||||
unicodedata.normalize('NFKD', rec.name).encode('ascii', 'ignore').decode('ascii'))),
|
||||
}
|
||||
self.db.get_session(rec).commit()
|
||||
job_id = self._app.pq.submit(
|
||||
|
|
|
@ -2,9 +2,9 @@ from datetime import datetime, timedelta
|
|||
|
||||
from nose.tools import raises, eq_
|
||||
|
||||
from forge import get_files_and_intervals, get_timefile_exact, round_timefile,\
|
||||
from .forge import get_files_and_intervals, get_timefile_exact, round_timefile,\
|
||||
get_timefile, mp3_join
|
||||
from config_manager import get_config
|
||||
from .config_manager import get_config
|
||||
|
||||
eight = datetime(2014, 5, 30, 20)
|
||||
nine = datetime(2014, 5, 30, 21)
|
||||
|
|
10
setup.py
10
setup.py
|
@ -13,15 +13,13 @@ setup(
|
|||
author_email="piuttosto@logorroici.org",
|
||||
packages=["techrec"],
|
||||
package_dir={"techrec": "server"},
|
||||
install_requires=[
|
||||
"Paste==1.7.5.1",
|
||||
"SQLAlchemy==0.8.3",
|
||||
"bottle==0.11.6",
|
||||
"wsgiref==0.1.2",
|
||||
],
|
||||
install_requires=["Paste~=3.2", "SQLAlchemy==0.8.3", "bottle~=0.12"],
|
||||
classifiers=["Programming Language :: Python :: 2.7"],
|
||||
entry_points={"console_scripts": ["techrec = techrec.cli:main"]},
|
||||
zip_safe=False,
|
||||
install_package_data=True,
|
||||
package_data={"techrec": ["static/**/*", "pages/*.html"]},
|
||||
test_suite="nose.collector",
|
||||
setup_requires=["nose>=1.0"],
|
||||
tests_requires=["nose>=1.0"],
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue