CC-2805: Airtime-import is failing

- catching IOexception.
This commit is contained in:
James 2011-09-13 10:35:25 -04:00
parent ab302b46ad
commit ac7e4566c0
1 changed files with 32 additions and 29 deletions

View File

@ -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] != '/'):
@ -294,7 +297,7 @@ except Exception, e:
if hasattr(e, 'msg'): if hasattr(e, 'msg'):
print "Error: "+e.msg print "Error: "+e.msg
else: else:
print "Error: "+e print "Error: ",e
sys.exit() sys.exit()
except SystemExit: except SystemExit:
printHelp() printHelp()