Exemplo n.º 1
0
def main():

    script = Script()
    script.add_argument('-f',
                        '--log-file',
                        default=DEFAULT_LOGFILE,
                        help='Log file')
    script.add_argument('-c',
                        '--configuration-file',
                        default=DEFAULT_CONFIGURATION_PATH,
                        help='Log file')
    script.add_argument('-h', '--redis-host', help='Redis host')
    script.add_argument('-r', '--redis-auth', help='Redis auth')
    args = script.parse_args()

    try:
        configuration = DaemonConfiguration(
            args.configuration_file,
            args.log_file,
            args.redis_host,
            args.redis_auth,
        )
    except Exception as e:
        script.exit(1, e)

    try:
        Daemon(**configuration).run()
    except MusicPlayerError as e:
        script.exit(1, e)
Exemplo n.º 2
0
def main():
    script = Script('pytunes-playlists',
                    'Import and export music player playlists')

    c = script.add_subcommand(ListCommand('list', 'List playlists'))
    c.add_argument('-s',
                   '--smart-playlists',
                   action='store_true',
                   help='Include smart playlists')
    c.add_argument('-y',
                   '--yearly',
                   action='store_true',
                   help='Order listed tracks by year')
    c.add_argument('-f', '--format', help='List formatting string')
    c.add_argument('playlists', nargs='*', help='Playlists to process')

    c = script.add_subcommand(
        ExportFilesCommand('export-files', 'Export playlists as files'))
    c.add_argument('-s',
                   '--smart-playlists',
                   action='store_true',
                   help='Include smart playlists')
    c.add_argument('-y',
                   '--yearly',
                   action='store_true',
                   help='Order exported tracks by year')
    c.add_argument('-f', '--format', help='Filename formatting string')
    c.add_argument('playlists', nargs='*', help='Playlists to process')

    c = script.add_subcommand(ExportCommand('export', 'Export m3u playlists'))
    script.add_argument('-D',
                        '--directory',
                        default=DEFAULT_DIRECTORY,
                        help='Playlist directory for m3u files')
    c.add_argument('-s',
                   '--smart-playlists',
                   action='store_true',
                   help='Include smart playlists')
    c.add_argument('-E',
                   '--ignore-empty',
                   action='store_true',
                   help='Ignore empty playlists')
    c.add_argument('playlists', nargs='*', help='Playlists to process')

    c = script.add_subcommand(ImportCommand('import', 'Import playlists'))
    c.add_argument('-s',
                   '--smart-playlists',
                   action='store_true',
                   help='Include smart playlists')
    c.add_argument('playlists', nargs='*', help='Playlists to process')

    c = script.add_subcommand(CreateCommand('create', 'Create playlists'))
    c.add_argument('names', nargs='*', help='Names of playlists to create')

    c = script.add_subcommand(RemoveCommand('remove', 'Remove playlists'))
    c.add_argument('names', nargs='*', help='Names of playlists to create')

    script.run()
Exemplo n.º 3
0
def main():
    """
    Main function  for vyos-config script
    """

    script = Script()

    script.add_subcommand(ListCommand())

    script.run()
Exemplo n.º 4
0
def main():
    script = Script()
    script.add_argument('--config',
                        default=DEFAULT_CONFIG_PATH,
                        help='Virtual machine directory')

    script.add_subcommand(ListCommand())
    script.add_subcommand(StatusCommand())
    script.add_subcommand(StartCommand())
    script.add_subcommand(StopCommand())
    script.add_subcommand(ResumeCommand())
    script.add_subcommand(SuspendCommand())
    script.add_subcommand(DetailsCommand())

    script.parse_args()
Exemplo n.º 5
0
def main():

    script = Script()

    c = script.add_subcommand(
        InfoCommand('info', 'Show playing track information'))
    c.add_argument('-v',
                   '--verbose',
                   action='store_true',
                   help='Verbose messages')

    c = script.add_subcommand(PlayCommand('play', 'Play/pause/jump to file'))
    c.add_argument('track', nargs='?', help='Track to play')

    c = script.add_subcommand(StopCommand('stop', 'Stop playback'))

    c = script.add_subcommand(
        PreviousTrackCommand('previous', 'Play previous tracks'))
    c = script.add_subcommand(NextTrackCommand('next', 'Play next tracks'))

    c = script.add_subcommand(
        ShuffleModeCommand('shuffle', 'Toggle or show suffle mode'))
    c.add_argument('mode',
                   nargs='?',
                   choices=(
                       'enable',
                       'disable',
                   ),
                   help='Enable or disable shuffle mode')

    c = script.add_subcommand(
        VolumeCommand('volume', 'Adjust or show playback volume'))
    c.add_argument('volume', nargs='?', help='Value to set')

    c = script.add_subcommand(
        UpdateIndexCommand('update-index', 'Update track index database'))

    c = script.add_subcommand(
        LookupDBCommand('lookup-index', 'Lookup track index from database'))
    c.add_argument('paths', nargs='*', help='Track paths to lookup')

    script.run()
Exemplo n.º 6
0
def main():

    script = Script(description='Update music player library metadata')
    script.add_argument('-c', '--codec', help='Music library default codec')
    script.add_argument('-l', '--music-path', help='Music library path')
    script.add_argument('-p',
                        '--position',
                        type=int,
                        help='Start from given position in library')
    script.add_argument('-m',
                        '--metadata',
                        action='store_true',
                        help='Update metadata')
    args = script.parse_args()

    client = Client()

    script.log.info('Loading music player library playlist')

    if args.position:
        try:
            client.library.jump(args.position)
        except ValueError:
            script.exit(
                1, 'Invalid position: {0} ({1:d} entries)'.format(
                    (args.position, len(client.library))))

    try:
        tree = MusicTree(tree_path=args.music_path)
        tree.load()
        tree_paths = tree.realpaths
    except Exception as e:
        script.exit(1, e)

    processed = 0
    progress_interval = PROGRESS_INTERVAL
    progress_start = time.time()
    start = time.time()
    app_files = {}

    script.log.info('Checking library files against music player database')

    for entry in client.library:
        processed += 1
        if processed % progress_interval == 0:
            progress_time = float(time.time() - progress_start)
            progress_rate = int(progress_interval / progress_time)
            script.log.info('Index {0:d} ({1:d} entries per second)'.format(
                processed, progress_rate))
            progress_start = time.time()

        try:
            if entry.path is None:
                try:
                    client.library.delete(entry)
                except MusicPlayerError as e:
                    print(e)
                continue
        except TypeError as e:
            print('Error processing entry {0}: {1}'.format(entry, e))
            continue

        try:
            path = normalized(os.path.realpath(entry.path))
        except AttributeError:
            script.log.info('Removing invalid entry (no path defined)')
            try:
                client.library.delete(entry)
            except MusicPlayerError as e:
                print(e)
            continue

        if path not in tree_paths:
            if not os.path.isfile(path):
                script.log.info('Removing non-existing: "}0}"'.format(path))
                try:
                    client.library.delete(entry)
                except MusicPlayerError as e:
                    print(e)
            else:
                script.log.info('File outside tree: {0}'.format(path))

        elif path not in app_files:
            app_files[path] = entry
            if args.metadata:
                mtime = os.stat(path).st_mtime
                if int(entry.modification_date.strftime('%s')) >= mtime:
                    continue

                song = Track(entry.path)
                if entry.syncTags(song):
                    client.library.__next = entry.index

        else:
            script.log.info('Removing duplicate: {0}'.format(entry.path))
            try:
                client.library.delete(entry)
            except MusicPlayerError as e:
                print(e)

    loadtime = float(time.time() - start)
    script.log.info('Checked {0:d} files in {1:4.2f} seconds'.format(
        processed, loadtime))

    start = time.time()
    processed = 0

    script.log.info('Checking music player database against tree files')

    if args.position is None:

        for path in sorted(tree_paths.keys()):

            if path not in app_files:
                script.log.info('Adding: {0}'.format(path))
                try:
                    client.library.add(path)
                except ValueError as e:
                    print(e)

            processed += 1
            if processed % 1000 == 0:
                script.log.debug('Processed: {0:d} entries'.format(processed))

    loadtime = float(time.time() - start)
    script.log.info('Checked {0:d} files in {1:2.2f} seconds'.format(
        processed, loadtime))
Exemplo n.º 7
0
 def __init__(self, description=None):
     object.__setattr__(self, 'state_code', NAGIOS_INITIAL_STATE)
     self.message = 'UNINITIALIZED'
     self.parser = Script(description=description)