From 5d8f87208be1d5ac6c5b75cad74782d8cb5de157 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 9 Sep 2011 16:12:21 -0400 Subject: [PATCH 1/5] CC-2659: airtime-import: displaying help text on all exception - it's displaying help text on all exception and unknown errors --- utils/airtime-import/airtime-import.py | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/utils/airtime-import/airtime-import.py b/utils/airtime-import/airtime-import.py index 014428702..4b7889c81 100644 --- a/utils/airtime-import/airtime-import.py +++ b/utils/airtime-import/airtime-import.py @@ -84,10 +84,8 @@ def checkOtherOption(args): def errorIfMultipleOption(args, msg=''): if(checkOtherOption(args)): if(msg != ''): - printHelp() raise OptionValueError(msg) else: - printHelp() raise OptionValueError("This option cannot be combined with other options") def printHelp(): @@ -123,7 +121,6 @@ There are two ways to import audio files into Airtime: def CopyAction(option, opt, value, parser): errorIfMultipleOption(parser.rargs) if(len(parser.rargs) == 0 ): - printHelp() raise OptionValueError("No argument found. This option requires at least one argument.") stor = helper_get_stor_dir() if(stor is None): @@ -134,7 +131,6 @@ def CopyAction(option, opt, value, parser): def MoveAction(option, opt, value, parser): errorIfMultipleOption(parser.rargs) if(len(parser.rargs) == 0 ): - printHelp() raise OptionValueError("No argument found. This option requires at least one argument.") stor = helper_get_stor_dir() if(stor is None): @@ -145,10 +141,8 @@ def MoveAction(option, opt, value, parser): def WatchAddAction(option, opt, value, parser): errorIfMultipleOption(parser.rargs) if(len(parser.rargs) > 1): - printHelp() raise OptionValueError("Too many arguments. This option requires exactly one argument.") elif(len(parser.rargs) == 0 ): - printHelp() raise OptionValueError("No argument found. This option requires exactly one argument.") path = parser.rargs[0] if (path[0] == "/" or path[0] == "~"): @@ -171,7 +165,6 @@ def WatchAddAction(option, opt, value, parser): def WatchListAction(option, opt, value, parser): errorIfMultipleOption(parser.rargs) if(len(parser.rargs) > 0): - printHelp() raise OptionValueError("This option doesn't take any arguments.") res = api_client.list_all_watched_dirs() if(res is None): @@ -188,10 +181,8 @@ def WatchListAction(option, opt, value, parser): def WatchRemoveAction(option, opt, value, parser): errorIfMultipleOption(parser.rargs) if(len(parser.rargs) > 1): - printHelp() raise OptionValueError("Too many arguments. This option requires exactly one argument.") elif(len(parser.rargs) == 0 ): - printHelp() raise OptionValueError("No argument found. This option requires exactly one argument.") path = parser.rargs[0] if (path[0] == "/" or path[0] == "~"): @@ -234,10 +225,8 @@ def StorageSetAction(option, opt, value, parser): sys.exit(1) if(len(parser.rargs) > 1): - printHelp() raise OptionValueError("Too many arguments. This option requires exactly one argument.") elif(len(parser.rargs) == 0 ): - printHelp() raise OptionValueError("No argument found. This option requires exactly one argument.") path = parser.rargs[0] @@ -261,10 +250,13 @@ def StorageSetAction(option, opt, value, parser): def StorageGetAction(option, opt, value, parser): errorIfMultipleOption(parser.rargs) if(len(parser.rargs) > 0): - printHelp() raise OptionValueError("This option does not take any arguments.") 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...]] [--watch-add DIR] [--watch-list] [--watch-remove DIR] [--storage-dir-set DIR] [--storage-dir-get]""" @@ -294,7 +286,16 @@ if(len(sys.argv) == 1 or '-' not in sys.argv[1]): printHelp() sys.exit() -(option, args) = parser.parse_args() +try: + (option, args) = parser.parse_args() +except Exception, e: + printHelp() + print "Error: "+e.msg + sys.exit() +except SystemExit: + printHelp() + sys.exit() + if option.help: printHelp() sys.exit() From ac44ae7191925cd48ee851403288a4f0e630cf1f Mon Sep 17 00:00:00 2001 From: James Date: Fri, 9 Sep 2011 17:08:23 -0400 Subject: [PATCH 2/5] CC-2659: airtime-import: displaying help text on all exception - when it cannot communicate to Airtime Server, it displays just error msg --- utils/airtime-import/airtime-import.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/airtime-import/airtime-import.py b/utils/airtime-import/airtime-import.py index 4b7889c81..d5b0d3246 100644 --- a/utils/airtime-import/airtime-import.py +++ b/utils/airtime-import/airtime-import.py @@ -124,7 +124,8 @@ def CopyAction(option, opt, value, parser): raise OptionValueError("No argument found. This option requires at least one argument.") stor = helper_get_stor_dir() if(stor is None): - exit("Unable to connect to the Airtime server.") + print "Unable to connect to the Airtime server." + return dest = stor+"organize/" copy_or_move_files_to(parser.rargs, dest, 'copy') From ab302b46ad9540d24627fbe1ce64ec60b56d2217 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 12 Sep 2011 13:08:02 -0400 Subject: [PATCH 3/5] CC-2805: Airtime-import is failing - fixed --- utils/airtime-import/airtime-import.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/airtime-import/airtime-import.py b/utils/airtime-import/airtime-import.py index d5b0d3246..9eacf7648 100644 --- a/utils/airtime-import/airtime-import.py +++ b/utils/airtime-import/airtime-import.py @@ -291,7 +291,10 @@ try: (option, args) = parser.parse_args() except Exception, e: printHelp() - print "Error: "+e.msg + if hasattr(e, 'msg'): + print "Error: "+e.msg + else: + print "Error: "+e sys.exit() except SystemExit: printHelp() From cf7f278e19e0a201735a2dd3fc9f5205d5c53ab0 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Sep 2011 14:52:56 -0400 Subject: [PATCH 4/5] CC-2802: When upgrading 1.8.2->1.9.4, .htaccess is being written with "Toronto/America" --- .../airtime-1.9.4/airtime-upgrade.php | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/install_minimal/upgrades/airtime-1.9.4/airtime-upgrade.php b/install_minimal/upgrades/airtime-1.9.4/airtime-upgrade.php index 41d35436e..6751db292 100644 --- a/install_minimal/upgrades/airtime-1.9.4/airtime-upgrade.php +++ b/install_minimal/upgrades/airtime-1.9.4/airtime-upgrade.php @@ -19,11 +19,58 @@ class Airtime194Upgrade{ exec("mkdir -p ".$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']; Airtime194Upgrade::InstallAirtimePhpServerCode($phpDir); +Airtime194Upgrade::ModifyHtAccessTimezone($phpDir); Airtime194Upgrade::upgradeLiquidsoapCfgPerms(); + From ac7e4566c0df20c469e9b5b26cdb93178a4faa0f Mon Sep 17 00:00:00 2001 From: James Date: Tue, 13 Sep 2011 10:35:25 -0400 Subject: [PATCH 5/5] CC-2805: Airtime-import is failing - catching IOexception. --- utils/airtime-import/airtime-import.py | 61 ++++++++++++++------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/utils/airtime-import/airtime-import.py b/utils/airtime-import/airtime-import.py index 9eacf7648..746f3f082 100644 --- a/utils/airtime-import/airtime-import.py +++ b/utils/airtime-import/airtime-import.py @@ -31,34 +31,37 @@ api_client = apc.api_client_factory(config) # copy or move files # flag should be 'copy' or 'move' def copy_or_move_files_to(paths, dest, flag): - for path in paths: - if (path[0] == "/" or path[0] == "~"): - path = os.path.realpath(path) - else: - path = currentDir+path - path = apc.encode_to(path, 'utf-8') - dest = apc.encode_to(dest, 'utf-8') - if(os.path.exists(path)): - if(os.path.isdir(path)): - path = format_dir_string(path) - #construct full path - sub_path = [] - for temp in os.listdir(path): - sub_path.append(path+temp) - copy_or_move_files_to(sub_path, dest, flag) - elif(os.path.isfile(path)): - #copy file to dest - ext = os.path.splitext(path)[1] - if( 'mp3' in ext or 'ogg' in ext ): - destfile = dest+os.path.basename(path) - if(flag == 'copy'): - print "Copying %(src)s to %(dest)s..." % {'src':path, 'dest':destfile} - shutil.copyfile(path, destfile) - elif(flag == 'move'): - print "Moving %(src)s to %(dest)s..." % {'src':path, 'dest':destfile} - shutil.move(path, destfile) - else: - print "Cannot find file or path: %s" % path + try: + for path in paths: + if (path[0] == "/" or path[0] == "~"): + path = os.path.realpath(path) + else: + path = currentDir+path + path = apc.encode_to(path, 'utf-8') + dest = apc.encode_to(dest, 'utf-8') + if(os.path.exists(path)): + if(os.path.isdir(path)): + path = format_dir_string(path) + #construct full path + sub_path = [] + for temp in os.listdir(path): + sub_path.append(path+temp) + copy_or_move_files_to(sub_path, dest, flag) + elif(os.path.isfile(path)): + #copy file to dest + ext = os.path.splitext(path)[1] + if( 'mp3' in ext or 'ogg' in ext ): + destfile = dest+os.path.basename(path) + if(flag == 'copy'): + print "Copying %(src)s to %(dest)s..." % {'src':path, 'dest':destfile} + shutil.copyfile(path, destfile) + elif(flag == 'move'): + print "Moving %(src)s to %(dest)s..." % {'src':path, 'dest':destfile} + shutil.move(path, destfile) + else: + print "Cannot find file or path: %s" % path + except Exception as e: + print "Error: ", e def format_dir_string(path): if(path[-1] != '/'): @@ -294,7 +297,7 @@ except Exception, e: if hasattr(e, 'msg'): print "Error: "+e.msg else: - print "Error: "+e + print "Error: ",e sys.exit() except SystemExit: printHelp()