From: kaliko Date: Fri, 11 Jun 2010 16:28:37 +0000 (+0000) Subject: * [mfade] convert mfade to use the new framework X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=bc382cb2c3140986efbf1d8786e2a58655c26b16;p=mpd-goodies.git * [mfade] convert mfade to use the new framework * [crop] updates crop acoording to changes in MPDClass * [mpdclass.py] some changes --- diff --git a/crop b/crop index 4a77bbb..9a08eb1 100755 --- a/crop +++ b/crop @@ -32,7 +32,7 @@ CROP_OPTS = list([ 'sw': ['-n', '--nbtracks'], 'type': 'int', 'dest': 'nb_tracks', - 'default': 60, + 'default': 6, 'metavar': '', 'help': 'keep tracks before currently played.'}, ]) @@ -42,20 +42,20 @@ class Crop(StartOpt, MPDClass): """ script_info = dict({ 'version': VERSION, - 'prog_name': 'crop', + 'prog_name': NAME, 'description': 'Keep tracks before currently played, removed others.', }) def __init__(self): """""" - StartOpt.__init__(self, Crop.script_info, CROP_OPTS) + StartOpt.__init__(self, self.__class__.script_info, CROP_OPTS) MPDClass.__init__(self) self._run() def _run(self): """""" print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port) - self.mpdConnect({'host':self.cli_options.host, 'port':self.cli_options.port}) + self.mpdConnect() current_pos = int(self.client.currentsong().get('pos')) if current_pos <= self.cli_options.nb_tracks: self.client.disconnect() diff --git a/lib/mpdclass.py b/lib/mpdclass.py index 5a8f4f9..63a2f06 100755 --- a/lib/mpdclass.py +++ b/lib/mpdclass.py @@ -18,11 +18,11 @@ class MPDClass(object): def __init__(self): self.client = MPDClient() - def mpdConnect(self, con_id):#{{{ + def mpdConnect(self):#{{{ """ Simple wrapper to connect MPD. - con_id = {'host': 'MPD_server', 'port': 'MPD_server port'} """ + con_id = dict({'host':self.cli_options.host, 'port':self.cli_options.port}) try: self.client.connect(**con_id) except SocketError: diff --git a/lib/startop.py b/lib/startop.py index 0ede89a..44cb64a 100644 --- a/lib/startop.py +++ b/lib/startop.py @@ -66,8 +66,12 @@ class StartOpt(object): version = self.info.get('version') prog = self.info.get('prog_name') des = self.info.get('description') + if 'usage' in self.info: + usage = self.info.get('usage') + else: + usage = USAGE self.parser = OptionParser(version=version, - usage=USAGE, + usage=usage, prog=prog, description=des) con_id, passwd = get_mpd_environ() diff --git a/mfade b/mfade index 6b8616b..6666c8d 100755 --- a/mfade +++ b/mfade @@ -29,94 +29,87 @@ import sys from time import sleep -from lib.mpdutils import mconnect - -USAGE = """Usage: - -mfade [time [min|max]] - - * time in seconds - * min|max in percentage of volume - -when MPD is: -- not playing: fade in from 0% to max over time - default 10 minutes / 50% -- playing: fade out from current volume to min over time - default 10 minutes / 1/10 of current vol - -Manual or any external volume change will abort the script. -""" - - -class Sleep(object): - """ - """ - - def __init__(self): +from lib.mpdclass import MPDClass +from lib.startop import StartOpt + +NAME = 'mfade' +VERSION = '0.1' +USAGE = 'USAGE: %prog [--help] [options] [