From: kaliko Date: Sun, 13 Jun 2010 13:31:00 +0000 (+0000) Subject: * rewrote mtopls X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=fb86eb100710617fea5b6d0e4a7bc452fd016732;p=mpd-goodies.git * rewrote mtopls * crop : switch to arguments instead of options in CLI --- diff --git a/crop b/crop index 9a08eb1..2b255f1 100755 --- a/crop +++ b/crop @@ -26,16 +26,7 @@ from lib.startop import StartOpt NAME = 'crop' VERSION = '0.1' - -CROP_OPTS = list([ - { - 'sw': ['-n', '--nbtracks'], - 'type': 'int', - 'dest': 'nb_tracks', - 'default': 6, - 'metavar': '', - 'help': 'keep tracks before currently played.'}, - ]) +USAGE = 'USAGE: %prog [--help] | [ ]' class Crop(StartOpt, MPDClass): """ @@ -43,24 +34,37 @@ class Crop(StartOpt, MPDClass): script_info = dict({ 'version': VERSION, 'prog_name': NAME, - 'description': 'Keep tracks before currently played, removed others.', + 'description': 'Keep tracks before currently played, removed others. Default is to keep 6 tracks.', + 'usage': USAGE, }) def __init__(self): """""" - StartOpt.__init__(self, self.__class__.script_info, CROP_OPTS) + StartOpt.__init__(self, self.__class__.script_info, []) MPDClass.__init__(self) + self.nb_tracks = 6 + self._get_arg() self._run() + def _get_arg(self): + """""" + if not self.cli_args: + return True + try: + self.nb_tracks = int(self.cli_args[0]) + except ValueError, err: + self.parser.error('invalid argument, not a natural number? (%s)' % err) + def _run(self): """""" print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port) + print 'Keeping %i tracks' % self.nb_tracks self.mpdConnect() current_pos = int(self.client.currentsong().get('pos')) - if current_pos <= self.cli_options.nb_tracks: + if current_pos <= self.nb_tracks: self.client.disconnect() sys.exit(0) - while current_pos > self.cli_options.nb_tracks: + while current_pos > self.nb_tracks: self.client.delete(0) current_pos = int(self.client.currentsong().get('pos')) self.client.disconnect() diff --git a/mfade b/mfade index 6666c8d..de84f14 100755 --- a/mfade +++ b/mfade @@ -34,10 +34,10 @@ from lib.startop import StartOpt NAME = 'mfade' VERSION = '0.1' -USAGE = 'USAGE: %prog [--help] [options] [