Merge branch '1.9.1' into devel
This commit is contained in:
commit
e6f7640c90
|
@ -19,11 +19,58 @@ class Airtime194Upgrade{
|
||||||
exec("mkdir -p ".$phpDir);
|
exec("mkdir -p ".$phpDir);
|
||||||
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function ModifyHtAccessTimezone($phpDir){
|
||||||
|
$file = realpath($phpDir)."/public/.htaccess";
|
||||||
|
|
||||||
|
$fn = "/etc/timezone";
|
||||||
|
$handle = @fopen($fn, "r");
|
||||||
|
if ($handle){
|
||||||
|
$timezone = trim(fgets($handle, 4096));
|
||||||
|
fclose($handle);
|
||||||
|
} else {
|
||||||
|
echo "Could not open $fn";
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = "php_value date.timezone";
|
||||||
|
//the best way to do this is use cli utility "sed", but I don't have time to learn this
|
||||||
|
$handle = @fopen($file, "r");
|
||||||
|
if ($handle) {
|
||||||
|
while (($buffer = fgets($handle, 4096)) !== false) {
|
||||||
|
if (strlen($key) > $buffer){
|
||||||
|
if (substr($buffer, 0, strlen($key)) == $key){
|
||||||
|
$output[] = "$key \"$timezone\"".PHP_EOL;
|
||||||
|
} else {
|
||||||
|
$output[] = $buffer;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$output[] = $buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!feof($handle)) {
|
||||||
|
echo "Error: unexpected fgets() fail\n";
|
||||||
|
}
|
||||||
|
fclose($handle);
|
||||||
|
} else {
|
||||||
|
echo "Could not open $file";
|
||||||
|
}
|
||||||
|
|
||||||
|
$handle = @fopen($file, 'w');
|
||||||
|
if ($handle) {
|
||||||
|
foreach ($output as $line){
|
||||||
|
fwrite($handle, $line);
|
||||||
|
}
|
||||||
|
fclose($handle);
|
||||||
|
} else {
|
||||||
|
echo "Could not open $file";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$values = parse_ini_file(AirtimeIni194::CONF_FILE_AIRTIME, true);
|
$values = parse_ini_file(Airtime194Upgrade::CONF_FILE_AIRTIME, true);
|
||||||
$phpDir = $values['general']['airtime_dir'];
|
$phpDir = $values['general']['airtime_dir'];
|
||||||
Airtime194Upgrade::InstallAirtimePhpServerCode($phpDir);
|
Airtime194Upgrade::InstallAirtimePhpServerCode($phpDir);
|
||||||
|
Airtime194Upgrade::ModifyHtAccessTimezone($phpDir);
|
||||||
Airtime194Upgrade::upgradeLiquidsoapCfgPerms();
|
Airtime194Upgrade::upgradeLiquidsoapCfgPerms();
|
||||||
|
|
||||||
|
|
|
@ -31,34 +31,37 @@ api_client = apc.api_client_factory(config)
|
||||||
# copy or move files
|
# copy or move files
|
||||||
# flag should be 'copy' or 'move'
|
# flag should be 'copy' or 'move'
|
||||||
def copy_or_move_files_to(paths, dest, flag):
|
def copy_or_move_files_to(paths, dest, flag):
|
||||||
for path in paths:
|
try:
|
||||||
if (path[0] == "/" or path[0] == "~"):
|
for path in paths:
|
||||||
path = os.path.realpath(path)
|
if (path[0] == "/" or path[0] == "~"):
|
||||||
else:
|
path = os.path.realpath(path)
|
||||||
path = currentDir+path
|
else:
|
||||||
path = apc.encode_to(path, 'utf-8')
|
path = currentDir+path
|
||||||
dest = apc.encode_to(dest, 'utf-8')
|
path = apc.encode_to(path, 'utf-8')
|
||||||
if(os.path.exists(path)):
|
dest = apc.encode_to(dest, 'utf-8')
|
||||||
if(os.path.isdir(path)):
|
if(os.path.exists(path)):
|
||||||
path = format_dir_string(path)
|
if(os.path.isdir(path)):
|
||||||
#construct full path
|
path = format_dir_string(path)
|
||||||
sub_path = []
|
#construct full path
|
||||||
for temp in os.listdir(path):
|
sub_path = []
|
||||||
sub_path.append(path+temp)
|
for temp in os.listdir(path):
|
||||||
copy_or_move_files_to(sub_path, dest, flag)
|
sub_path.append(path+temp)
|
||||||
elif(os.path.isfile(path)):
|
copy_or_move_files_to(sub_path, dest, flag)
|
||||||
#copy file to dest
|
elif(os.path.isfile(path)):
|
||||||
ext = os.path.splitext(path)[1]
|
#copy file to dest
|
||||||
if( 'mp3' in ext or 'ogg' in ext ):
|
ext = os.path.splitext(path)[1]
|
||||||
destfile = dest+os.path.basename(path)
|
if( 'mp3' in ext or 'ogg' in ext ):
|
||||||
if(flag == 'copy'):
|
destfile = dest+os.path.basename(path)
|
||||||
print "Copying %(src)s to %(dest)s..." % {'src':path, 'dest':destfile}
|
if(flag == 'copy'):
|
||||||
shutil.copyfile(path, destfile)
|
print "Copying %(src)s to %(dest)s..." % {'src':path, 'dest':destfile}
|
||||||
elif(flag == 'move'):
|
shutil.copyfile(path, destfile)
|
||||||
print "Moving %(src)s to %(dest)s..." % {'src':path, 'dest':destfile}
|
elif(flag == 'move'):
|
||||||
shutil.move(path, destfile)
|
print "Moving %(src)s to %(dest)s..." % {'src':path, 'dest':destfile}
|
||||||
else:
|
shutil.move(path, destfile)
|
||||||
print "Cannot find file or path: %s" % path
|
else:
|
||||||
|
print "Cannot find file or path: %s" % path
|
||||||
|
except Exception as e:
|
||||||
|
print "Error: ", e
|
||||||
|
|
||||||
def format_dir_string(path):
|
def format_dir_string(path):
|
||||||
if(path[-1] != '/'):
|
if(path[-1] != '/'):
|
||||||
|
@ -84,10 +87,8 @@ def checkOtherOption(args):
|
||||||
def errorIfMultipleOption(args, msg=''):
|
def errorIfMultipleOption(args, msg=''):
|
||||||
if(checkOtherOption(args)):
|
if(checkOtherOption(args)):
|
||||||
if(msg != ''):
|
if(msg != ''):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError(msg)
|
raise OptionValueError(msg)
|
||||||
else:
|
else:
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("This option cannot be combined with other options")
|
raise OptionValueError("This option cannot be combined with other options")
|
||||||
|
|
||||||
def printHelp():
|
def printHelp():
|
||||||
|
@ -123,18 +124,17 @@ There are two ways to import audio files into Airtime:
|
||||||
def CopyAction(option, opt, value, parser):
|
def CopyAction(option, opt, value, parser):
|
||||||
errorIfMultipleOption(parser.rargs)
|
errorIfMultipleOption(parser.rargs)
|
||||||
if(len(parser.rargs) == 0 ):
|
if(len(parser.rargs) == 0 ):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("No argument found. This option requires at least one argument.")
|
raise OptionValueError("No argument found. This option requires at least one argument.")
|
||||||
stor = helper_get_stor_dir()
|
stor = helper_get_stor_dir()
|
||||||
if(stor is None):
|
if(stor is None):
|
||||||
exit("Unable to connect to the Airtime server.")
|
print "Unable to connect to the Airtime server."
|
||||||
|
return
|
||||||
dest = stor+"organize/"
|
dest = stor+"organize/"
|
||||||
copy_or_move_files_to(parser.rargs, dest, 'copy')
|
copy_or_move_files_to(parser.rargs, dest, 'copy')
|
||||||
|
|
||||||
def MoveAction(option, opt, value, parser):
|
def MoveAction(option, opt, value, parser):
|
||||||
errorIfMultipleOption(parser.rargs)
|
errorIfMultipleOption(parser.rargs)
|
||||||
if(len(parser.rargs) == 0 ):
|
if(len(parser.rargs) == 0 ):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("No argument found. This option requires at least one argument.")
|
raise OptionValueError("No argument found. This option requires at least one argument.")
|
||||||
stor = helper_get_stor_dir()
|
stor = helper_get_stor_dir()
|
||||||
if(stor is None):
|
if(stor is None):
|
||||||
|
@ -145,10 +145,8 @@ def MoveAction(option, opt, value, parser):
|
||||||
def WatchAddAction(option, opt, value, parser):
|
def WatchAddAction(option, opt, value, parser):
|
||||||
errorIfMultipleOption(parser.rargs)
|
errorIfMultipleOption(parser.rargs)
|
||||||
if(len(parser.rargs) > 1):
|
if(len(parser.rargs) > 1):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("Too many arguments. This option requires exactly one argument.")
|
raise OptionValueError("Too many arguments. This option requires exactly one argument.")
|
||||||
elif(len(parser.rargs) == 0 ):
|
elif(len(parser.rargs) == 0 ):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("No argument found. This option requires exactly one argument.")
|
raise OptionValueError("No argument found. This option requires exactly one argument.")
|
||||||
path = parser.rargs[0]
|
path = parser.rargs[0]
|
||||||
if (path[0] == "/" or path[0] == "~"):
|
if (path[0] == "/" or path[0] == "~"):
|
||||||
|
@ -171,7 +169,6 @@ def WatchAddAction(option, opt, value, parser):
|
||||||
def WatchListAction(option, opt, value, parser):
|
def WatchListAction(option, opt, value, parser):
|
||||||
errorIfMultipleOption(parser.rargs)
|
errorIfMultipleOption(parser.rargs)
|
||||||
if(len(parser.rargs) > 0):
|
if(len(parser.rargs) > 0):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("This option doesn't take any arguments.")
|
raise OptionValueError("This option doesn't take any arguments.")
|
||||||
res = api_client.list_all_watched_dirs()
|
res = api_client.list_all_watched_dirs()
|
||||||
if(res is None):
|
if(res is None):
|
||||||
|
@ -188,10 +185,8 @@ def WatchListAction(option, opt, value, parser):
|
||||||
def WatchRemoveAction(option, opt, value, parser):
|
def WatchRemoveAction(option, opt, value, parser):
|
||||||
errorIfMultipleOption(parser.rargs)
|
errorIfMultipleOption(parser.rargs)
|
||||||
if(len(parser.rargs) > 1):
|
if(len(parser.rargs) > 1):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("Too many arguments. This option requires exactly one argument.")
|
raise OptionValueError("Too many arguments. This option requires exactly one argument.")
|
||||||
elif(len(parser.rargs) == 0 ):
|
elif(len(parser.rargs) == 0 ):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("No argument found. This option requires exactly one argument.")
|
raise OptionValueError("No argument found. This option requires exactly one argument.")
|
||||||
path = parser.rargs[0]
|
path = parser.rargs[0]
|
||||||
if (path[0] == "/" or path[0] == "~"):
|
if (path[0] == "/" or path[0] == "~"):
|
||||||
|
@ -234,10 +229,8 @@ def StorageSetAction(option, opt, value, parser):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if(len(parser.rargs) > 1):
|
if(len(parser.rargs) > 1):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("Too many arguments. This option requires exactly one argument.")
|
raise OptionValueError("Too many arguments. This option requires exactly one argument.")
|
||||||
elif(len(parser.rargs) == 0 ):
|
elif(len(parser.rargs) == 0 ):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("No argument found. This option requires exactly one argument.")
|
raise OptionValueError("No argument found. This option requires exactly one argument.")
|
||||||
|
|
||||||
path = parser.rargs[0]
|
path = parser.rargs[0]
|
||||||
|
@ -261,10 +254,13 @@ def StorageSetAction(option, opt, value, parser):
|
||||||
def StorageGetAction(option, opt, value, parser):
|
def StorageGetAction(option, opt, value, parser):
|
||||||
errorIfMultipleOption(parser.rargs)
|
errorIfMultipleOption(parser.rargs)
|
||||||
if(len(parser.rargs) > 0):
|
if(len(parser.rargs) > 0):
|
||||||
printHelp()
|
|
||||||
raise OptionValueError("This option does not take any arguments.")
|
raise OptionValueError("This option does not take any arguments.")
|
||||||
print helper_get_stor_dir()
|
print helper_get_stor_dir()
|
||||||
|
|
||||||
|
class OptionValueError(RuntimeError):
|
||||||
|
def __init__(self, msg):
|
||||||
|
self.msg = msg
|
||||||
|
|
||||||
usage = """[-c|--copy FILE/DIR [FILE/DIR...]] [-m|--move FILE/DIR [FILE/DIR...]]
|
usage = """[-c|--copy FILE/DIR [FILE/DIR...]] [-m|--move FILE/DIR [FILE/DIR...]]
|
||||||
[--watch-add DIR] [--watch-list] [--watch-remove DIR]
|
[--watch-add DIR] [--watch-list] [--watch-remove DIR]
|
||||||
[--storage-dir-set DIR] [--storage-dir-get]"""
|
[--storage-dir-set DIR] [--storage-dir-get]"""
|
||||||
|
@ -294,7 +290,19 @@ if(len(sys.argv) == 1 or '-' not in sys.argv[1]):
|
||||||
printHelp()
|
printHelp()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
(option, args) = parser.parse_args()
|
try:
|
||||||
|
(option, args) = parser.parse_args()
|
||||||
|
except Exception, e:
|
||||||
|
printHelp()
|
||||||
|
if hasattr(e, 'msg'):
|
||||||
|
print "Error: "+e.msg
|
||||||
|
else:
|
||||||
|
print "Error: ",e
|
||||||
|
sys.exit()
|
||||||
|
except SystemExit:
|
||||||
|
printHelp()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if option.help:
|
if option.help:
|
||||||
printHelp()
|
printHelp()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
Loading…
Reference in New Issue