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()