Formatted spaces.

This commit is contained in:
Rudi Grinberg 2012-10-29 11:40:23 -04:00
parent 3b51c93766
commit 35a9e77062
1 changed files with 17 additions and 17 deletions

View File

@ -21,7 +21,7 @@ logger.addHandler(ch)
if (os.geteuid() != 0): if (os.geteuid() != 0):
print 'Must be a root user.' print 'Must be a root user.'
sys.exit() sys.exit()
# loading config file # loading config file
try: try:
config = ConfigObj('/etc/airtime/media-monitor.cfg') config = ConfigObj('/etc/airtime/media-monitor.cfg')
@ -66,12 +66,12 @@ def copy_or_move_files_to(paths, dest, flag):
print "Cannot find file or path: %s" % path print "Cannot find file or path: %s" % path
except Exception as e: except Exception as e:
print "Error: ", e print "Error: ", e
def format_dir_string(path): def format_dir_string(path):
if(path[-1] != '/'): if(path[-1] != '/'):
path = path+'/' path = path+'/'
return path return path
def helper_get_stor_dir(): def helper_get_stor_dir():
res = api_client.list_all_watched_dirs() res = api_client.list_all_watched_dirs()
if(res is None): if(res is None):
@ -87,18 +87,18 @@ def checkOtherOption(args):
for i in args: for i in args:
if(i[0] == '-'): if(i[0] == '-'):
return True return True
def errorIfMultipleOption(args, msg=''): def errorIfMultipleOption(args, msg=''):
if(checkOtherOption(args)): if(checkOtherOption(args)):
if(msg != ''): if(msg != ''):
raise OptionValueError(msg) raise OptionValueError(msg)
else: else:
raise OptionValueError("This option cannot be combined with other options") raise OptionValueError("This option cannot be combined with other options")
def printHelp(): def printHelp():
storage_dir = helper_get_stor_dir() storage_dir = helper_get_stor_dir()
if(storage_dir is None): if(storage_dir is None):
storage_dir = "Unknown" storage_dir = "Unknown"
else: else:
storage_dir += "imported/" storage_dir += "imported/"
print """ print """
@ -111,15 +111,15 @@ There are two ways to import audio files into Airtime:
Copied or moved files will be placed into the folder: Copied or moved files will be placed into the folder:
%s %s
Files will be automatically organized into the structure Files will be automatically organized into the structure
"Artist/Album/TrackNumber-TrackName-Bitrate.file_extension". "Artist/Album/TrackNumber-TrackName-Bitrate.file_extension".
2) Use airtime-import to add a folder to the Airtime library ("watch" a folder). 2) Use airtime-import to add a folder to the Airtime library ("watch" a folder).
All the files in the watched folder will be imported to Airtime and the All the files in the watched folder will be imported to Airtime and the
folder will be monitored to automatically detect any changes. Hence any folder will be monitored to automatically detect any changes. Hence any
changes done in the folder(add, delete, edit a file) will trigger changes done in the folder(add, delete, edit a file) will trigger
updates in Airtime library. updates in Airtime library.
""" % storage_dir """ % storage_dir
parser.print_help() parser.print_help()
@ -209,7 +209,7 @@ def WatchRemoveAction(option, opt, value, parser):
print "Removing the watch folder failed: %s" % res['msg']['error'] print "Removing the watch folder failed: %s" % res['msg']['error']
else: else:
print "The given path is not a directory: %s" % path print "The given path is not a directory: %s" % path
def StorageSetAction(option, opt, value, parser): def StorageSetAction(option, opt, value, parser):
bypass = False bypass = False
isF = '-f' in parser.rargs isF = '-f' in parser.rargs
@ -231,12 +231,12 @@ def StorageSetAction(option, opt, value, parser):
confirm = confirm or 'N' confirm = confirm or 'N'
if(confirm == 'n' or confirm =='N'): if(confirm == 'n' or confirm =='N'):
sys.exit(1) sys.exit(1)
if(len(parser.rargs) > 1): if(len(parser.rargs) > 1):
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 ):
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] == "~"):
path = os.path.realpath(path) path = os.path.realpath(path)
@ -254,17 +254,17 @@ def StorageSetAction(option, opt, value, parser):
print "Setting storage folder failed: %s" % res['msg']['error'] print "Setting storage folder failed: %s" % res['msg']['error']
else: else:
print "The given path is not a directory: %s" % path print "The given path is not a directory: %s" % path
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):
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): class OptionValueError(RuntimeError):
def __init__(self, msg): def __init__(self, msg):
self.msg = 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]"""
@ -293,7 +293,7 @@ if('-h' in sys.argv):
if(len(sys.argv) == 1 or '-' not in sys.argv[1]): if(len(sys.argv) == 1 or '-' not in sys.argv[1]):
printHelp() printHelp()
sys.exit() sys.exit()
try: try:
(option, args) = parser.parse_args() (option, args) = parser.parse_args()
except Exception, e: except Exception, e:
@ -306,7 +306,7 @@ except Exception, e:
except SystemExit: except SystemExit:
printHelp() printHelp()
sys.exit() sys.exit()
if option.help: if option.help:
printHelp() printHelp()
sys.exit() sys.exit()