Dodanie brakujcego pliku, dodanie pliku konfiguracyjnego, argumenty
parsowane sa teraz przez ArgumentParser
This commit is contained in:
parent
575c30bbe9
commit
77927e3490
53
common_functions.py
Normal file
53
common_functions.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import sys, os
|
||||||
|
import ConfigParser
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
def stdin_thread(manag):
|
||||||
|
try:
|
||||||
|
fd = sys.stdin.fileno()
|
||||||
|
while True:
|
||||||
|
data = os.read(fd, 1024)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
manag.execute_command(data.rstrip('\n\r'))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_configuration():
|
||||||
|
parser = argparse.ArgumentParser(description='Synchronize multiple players over the web.',
|
||||||
|
epilog='If no options supplied config values will be used')
|
||||||
|
parser.add_argument('host', metavar='host', type=str, nargs='?', help='server\'s address')
|
||||||
|
parser.add_argument('name', metavar='name', type=str, nargs='?', help='desired username')
|
||||||
|
parser.add_argument('args', metavar='opts', type=str, nargs='*', help='player options, if you need to pass options starting with - prepend them with single \'--\' argument')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
config = ConfigParser.RawConfigParser(allow_no_value=True)
|
||||||
|
config.read('syncplay.ini')
|
||||||
|
try:
|
||||||
|
if(args.host == None):
|
||||||
|
host = config.get('sync', 'host')
|
||||||
|
else:
|
||||||
|
host = args.host
|
||||||
|
if(args.name == None):
|
||||||
|
name = config.get('sync', 'name')
|
||||||
|
else:
|
||||||
|
name = args.name
|
||||||
|
except ConfigParser.NoSectionError:
|
||||||
|
exit("Host or username not specified")
|
||||||
|
|
||||||
|
with open('syncplay.ini', 'wb') as configfile:
|
||||||
|
try:
|
||||||
|
config.set('sync', 'host' ,host)
|
||||||
|
config.set('sync', 'name' ,name)
|
||||||
|
except ConfigParser.NoSectionError:
|
||||||
|
config.add_section('sync')
|
||||||
|
config.set('sync', 'host' ,host)
|
||||||
|
config.set('sync', 'name' ,name)
|
||||||
|
config.write(configfile)
|
||||||
|
|
||||||
|
if ':' in host:
|
||||||
|
host, port = host.split(':', 1)
|
||||||
|
port = int(port)
|
||||||
|
else:
|
||||||
|
port = 8999
|
||||||
|
return host,port,name,args.args
|
||||||
@ -4,7 +4,7 @@ from setuptools import find_packages
|
|||||||
|
|
||||||
common_info = dict(
|
common_info = dict(
|
||||||
name = 'SyncPlay',
|
name = 'SyncPlay',
|
||||||
version = '0.1',
|
version = '0.2',
|
||||||
author = 'Tomasz Kowalczyk, Uriziel',
|
author = 'Tomasz Kowalczyk, Uriziel',
|
||||||
author_email = 'code@fluxid.pl',
|
author_email = 'code@fluxid.pl',
|
||||||
description = 'Solution to synchronize playback of multiple MPlayer and MPC-HC instances over the network.',
|
description = 'Solution to synchronize playback of multiple MPlayer and MPC-HC instances over the network.',
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from syncplay.players import mpc
|
|||||||
import common_functions
|
import common_functions
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
host,port, name = common_functions.get_configuration()
|
host, port, name, args = common_functions.get_configuration()
|
||||||
manager = client.Manager(host, port, name, lambda m: mpc.run_mpc(m))
|
manager = client.Manager(host, port, name, lambda m: mpc.run_mpc(m))
|
||||||
thread.start_new_thread(common_functions.stdin_thread, (manager,))
|
thread.start_new_thread(common_functions.stdin_thread, (manager,))
|
||||||
manager.start()
|
manager.start()
|
||||||
|
|||||||
@ -10,17 +10,8 @@ from syncplay.players import mplayer
|
|||||||
import common_functions
|
import common_functions
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = sys.argv[1:]
|
host, port, name, args = common_functions.get_configuration()
|
||||||
host = args.pop(0)
|
|
||||||
name = args.pop(0)
|
|
||||||
if ':' in host:
|
|
||||||
host, port = host.split(':', 1)
|
|
||||||
port = int(port)
|
|
||||||
else:
|
|
||||||
port = 8999
|
|
||||||
|
|
||||||
args.extend(('-slave', '-msglevel', 'all=1:global=4'))
|
args.extend(('-slave', '-msglevel', 'all=1:global=4'))
|
||||||
|
|
||||||
manager = client.Manager(host, port, name, lambda m: mplayer.run_mplayer(m, 'mplayer', args))
|
manager = client.Manager(host, port, name, lambda m: mplayer.run_mplayer(m, 'mplayer', args))
|
||||||
thread.start_new_thread(common_functions.stdin_thread, (manager,))
|
thread.start_new_thread(common_functions.stdin_thread, (manager,))
|
||||||
manager.start()
|
manager.start()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user