comparison python/dlna.py @ 757:af7b427b3b83

print config option
author Jeff Hammel <k0scist@gmail.com>
date Thu, 06 Aug 2015 18:06:35 -0700
parents 02aec49585ab
children
comparison
equal deleted inserted replaced
756:12f0be02e9cc 757:af7b427b3b83
29 parser.add_argument('-p', '--port', dest='port', default=8200, type=int, 29 parser.add_argument('-p', '--port', dest='port', default=8200, type=int,
30 help="port") 30 help="port")
31 parser.add_argument('-v', '--videos', dest='videos', nargs='+', 31 parser.add_argument('-v', '--videos', dest='videos', nargs='+',
32 help="videos") 32 help="videos")
33 parser.add_argument('audio', nargs='+') 33 parser.add_argument('audio', nargs='+')
34 parser.add_argument('--print', '--print-config', dest='print_config',
35 action='store_true', default=False,
36 help="write config to stdout and exit")
34 options = parser.parse_args(args) 37 options = parser.parse_args(args)
35 38
36 # dlna location 39 # dlna location
37 dlna = which('minidlnad') 40 dlna = which('minidlnad')
38 if not dlna: 41 if not dlna:
48 lines.extend([('media_dir', 'V,{}'.format(os.path.abspath(d))) 51 lines.extend([('media_dir', 'V,{}'.format(os.path.abspath(d)))
49 for d in options.audio]) 52 for d in options.audio])
50 config = '\n'.join(['{}={}'.format(*line) for line in lines]) 53 config = '\n'.join(['{}={}'.format(*line) for line in lines])
51 print (config) 54 print (config)
52 55
56 if options.print_config:
57 parser.exit()
58
53 fd, name = tempfile.mkstemp() 59 fd, name = tempfile.mkstemp()
54 os.write(fd, config) 60 os.write(fd, config)
55 os.close(fd) 61 os.close(fd)
56 62
57 command = [dlna, '-f', name, '-p', str(options.port)] 63 command = [dlna, '-f', name, '-p', str(options.port)]