Removed use of virtualenv in utils
This commit is contained in:
parent
19de887efb
commit
32c7e81685
|
@ -1,42 +1,79 @@
|
|||
#!/bin/bash
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2011 Sourcefabric O.P.S.
|
||||
#
|
||||
# This file is part of the Airtime project.
|
||||
# http://airtime.sourcefabric.org/
|
||||
#
|
||||
# Airtime is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Airtime is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Airtime; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# This script handles update cue-in/cue-out points for files that already exist
|
||||
# in Airtime's library.
|
||||
#
|
||||
exec 2>&1
|
||||
airtime_silan_script="airtime-silan.py"
|
||||
api_client_path="/usr/lib/airtime/"
|
||||
#!/usr/bin/python
|
||||
from configobj import ConfigObj
|
||||
from api_clients import api_client as apc
|
||||
|
||||
virtualenv_bin="/usr/lib/airtime/airtime_virtualenv/bin/"
|
||||
. ${virtualenv_bin}activate
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import traceback
|
||||
|
||||
export PYTHONPATH=${api_client_path}
|
||||
# create logger
|
||||
logger = logging.getLogger()
|
||||
|
||||
# Absolute path to this script
|
||||
SCRIPT=`readlink -f $0`
|
||||
# Absolute directory this script is in
|
||||
SCRIPTPATH=`dirname $SCRIPT`
|
||||
# no logging
|
||||
ch = logging.StreamHandler()
|
||||
logging.disable(50)
|
||||
|
||||
cd $SCRIPTPATH
|
||||
python ${airtime_silan_script}
|
||||
# add ch to logger
|
||||
logger.addHandler(ch)
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print 'Must be a root user.'
|
||||
sys.exit(1)
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('/etc/airtime/airtime.conf')
|
||||
except Exception, e:
|
||||
print('Error loading config file: %s', e)
|
||||
sys.exit(1)
|
||||
|
||||
api_client = apc.AirtimeApiClient(config)
|
||||
|
||||
try:
|
||||
# keep getting few rows at a time for current music_dir (stor
|
||||
# or watched folder).
|
||||
subtotal = 0
|
||||
while True:
|
||||
# return a list of pairs where the first value is the
|
||||
# file's database row id and the second value is the
|
||||
# filepath
|
||||
files = api_client.get_files_without_silan_value()
|
||||
total_files = len(files)
|
||||
if total_files == 0: break
|
||||
processed_data = []
|
||||
total = 0
|
||||
for f in files:
|
||||
full_path = f['fp']
|
||||
# silence detect(set default queue in and out)
|
||||
try:
|
||||
command = ['silan', '-b' '-f', 'JSON', full_path]
|
||||
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
|
||||
out = proc.communicate()[0].strip('\r\n')
|
||||
info = json.loads(out)
|
||||
data = {}
|
||||
data['cuein'] = str('{0:f}'.format(info['sound'][0][0]))
|
||||
data['cueout'] = str('{0:f}'.format(info['sound'][-1][1]))
|
||||
data['length'] = str('{0:f}'.format(info['file duration']))
|
||||
processed_data.append((f['id'], data))
|
||||
total += 1
|
||||
if total % 5 == 0:
|
||||
print "Total %s / %s files has been processed.." % (total, total_files)
|
||||
except Exception, e:
|
||||
print e
|
||||
print traceback.format_exc()
|
||||
print "Processed: %d songs" % total
|
||||
subtotal += total
|
||||
|
||||
try:
|
||||
print api_client.update_cue_values_by_silan(processed_data)
|
||||
except Exception ,e:
|
||||
print e
|
||||
print traceback.format_exc()
|
||||
print "Total %d songs Processed" % subtotal
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
print traceback.format_exc()
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
from configobj import ConfigObj
|
||||
from api_clients import api_client as apc
|
||||
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import traceback
|
||||
|
||||
# create logger
|
||||
logger = logging.getLogger()
|
||||
|
||||
# no logging
|
||||
ch = logging.StreamHandler()
|
||||
logging.disable(50)
|
||||
|
||||
# add ch to logger
|
||||
logger.addHandler(ch)
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print 'Must be a root user.'
|
||||
sys.exit(1)
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('/etc/airtime/airtime.conf')
|
||||
except Exception, e:
|
||||
print('Error loading config file: %s', e)
|
||||
sys.exit(1)
|
||||
|
||||
api_client = apc.AirtimeApiClient(config)
|
||||
|
||||
try:
|
||||
# keep getting few rows at a time for current music_dir (stor
|
||||
# or watched folder).
|
||||
subtotal = 0
|
||||
while True:
|
||||
# return a list of pairs where the first value is the
|
||||
# file's database row id and the second value is the
|
||||
# filepath
|
||||
files = api_client.get_files_without_silan_value()
|
||||
total_files = len(files)
|
||||
if total_files == 0: break
|
||||
processed_data = []
|
||||
total = 0
|
||||
for f in files:
|
||||
full_path = f['fp']
|
||||
# silence detect(set default queue in and out)
|
||||
try:
|
||||
command = ['silan', '-b' '-f', 'JSON', full_path]
|
||||
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
|
||||
out = proc.communicate()[0].strip('\r\n')
|
||||
info = json.loads(out)
|
||||
data = {}
|
||||
data['cuein'] = str('{0:f}'.format(info['sound'][0][0]))
|
||||
data['cueout'] = str('{0:f}'.format(info['sound'][-1][1]))
|
||||
data['length'] = str('{0:f}'.format(info['file duration']))
|
||||
processed_data.append((f['id'], data))
|
||||
total += 1
|
||||
if total % 5 == 0:
|
||||
print "Total %s / %s files has been processed.." % (total, total_files)
|
||||
except Exception, e:
|
||||
print e
|
||||
print traceback.format_exc()
|
||||
print "Processed: %d songs" % total
|
||||
subtotal += total
|
||||
|
||||
try:
|
||||
print api_client.update_cue_values_by_silan(processed_data)
|
||||
except Exception ,e:
|
||||
print e
|
||||
print traceback.format_exc()
|
||||
print "Total %d songs Processed" % subtotal
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
print traceback.format_exc()
|
|
@ -1,18 +0,0 @@
|
|||
#!/bin/bash
|
||||
#-------------------------------------------------------------------------------
|
||||
# Determine directories, files
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
virtualenv_bin="/usr/lib/airtime/airtime_virtualenv/bin/"
|
||||
. ${virtualenv_bin}activate
|
||||
|
||||
# Absolute path to this script
|
||||
SCRIPT=`readlink -f $0`
|
||||
# Absolute directory this script is in
|
||||
SCRIPTPATH=`dirname $SCRIPT`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Do import
|
||||
#-------------------------------------------------------------------------------
|
||||
invokePwd=$PWD
|
||||
cd $SCRIPTPATH && python airtime-update-db-settings.py
|
|
@ -1,87 +0,0 @@
|
|||
"""
|
||||
The purpose of this script is to consolidate into one location where
|
||||
we need to update database host, dbname, username and password.
|
||||
|
||||
This script reads from /etc/airtime/airtime.conf.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import ConfigParser
|
||||
import xml.dom.minidom
|
||||
from xml.dom.minidom import Node
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
airtime_conf = '/etc/airtime/airtime.conf'
|
||||
|
||||
#Read the universal values
|
||||
parser = ConfigParser.SafeConfigParser()
|
||||
parser.read(airtime_conf)
|
||||
|
||||
host = 'resources.db.params.host'
|
||||
dbname = 'resources.db.params.dbname'
|
||||
username = 'resources.db.params.username'
|
||||
password = 'resources.db.params.password'
|
||||
|
||||
airtime_dir = parser.get('general', 'airtime_dir')
|
||||
if os.path.exists(airtime_dir):
|
||||
print 'Airtime root folder found at %s' % airtime_dir
|
||||
else:
|
||||
print 'Could not find Airtime root folder specified by "airtime_dir" in %s' % airtime_conf
|
||||
sys.exit(1)
|
||||
|
||||
print ("Updating %s/application/configs/application.ini" % airtime_dir)
|
||||
f = file('%s/application/configs/application.ini' % airtime_dir,'r')
|
||||
file_lines = []
|
||||
|
||||
for line in f:
|
||||
if line[0:len(host)] == host:
|
||||
line= '%s = "%s"\n' % (host, parser.get('database', 'host'))
|
||||
elif line[0:len(dbname)] == dbname:
|
||||
line= '%s = "%s"\n' % (dbname, parser.get('database', 'dbname'))
|
||||
elif line[0:len(username)] == username:
|
||||
line= '%s = "%s"\n' % (username, parser.get('database', 'dbuser'))
|
||||
elif line[0:len(password)] == password:
|
||||
line= '%s = "%s"\n' % (password, parser.get('database', 'dbpass'))
|
||||
file_lines.append(line)
|
||||
f.close()
|
||||
|
||||
f = file('%s/application/configs/application.ini' % airtime_dir, 'w')
|
||||
f.writelines(file_lines)
|
||||
f.close()
|
||||
|
||||
|
||||
print ("Updating %s/build/build.properties" % airtime_dir)
|
||||
|
||||
f = file('%s/build/build.properties' % airtime_dir, 'r')
|
||||
file_lines = []
|
||||
|
||||
db_url = 'propel.database.url'
|
||||
|
||||
for line in f:
|
||||
if line[0:len(db_url)] == db_url:
|
||||
line = '%s = pgsql:host=%s dbname=%s user=%s password=%s\n' % \
|
||||
(db_url, parser.get('database', 'host'), parser.get('database', 'dbname'), parser.get('database', 'dbuser'), \
|
||||
parser.get('database', 'dbpass'))
|
||||
file_lines.append(line)
|
||||
f.close()
|
||||
|
||||
f = file('%s/build/build.properties' % airtime_dir, 'w')
|
||||
f.writelines(file_lines)
|
||||
f.close()
|
||||
|
||||
print ("Updating %s/build/runtime-conf.xml" % airtime_dir)
|
||||
|
||||
doc = xml.dom.minidom.parse('%s/build/runtime-conf.xml' % airtime_dir)
|
||||
|
||||
node = doc.getElementsByTagName("dsn")[0]
|
||||
node.firstChild.nodeValue = 'pgsql:host=%s;port=5432;dbname=%s;user=%s;password=%s' % (parser.get('database', 'host'), \
|
||||
parser.get('database', 'dbname'), parser.get('database', 'dbuser'), parser.get('database', 'dbpass'))
|
||||
|
||||
xml_file = open('%s/build/runtime-conf.xml' % airtime_dir, "w")
|
||||
xml_file.writelines(doc.toxml('utf-8'))
|
||||
xml_file.close()
|
||||
|
||||
print "Success!"
|
Loading…
Reference in New Issue