bug fixes on refactoring
This commit is contained in:
parent
177821e170
commit
321fb5a3a5
@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
from .network_utils import argumentCount, CommandProtocol
|
from .network_utils import argumentCount, CommandProtocol
|
||||||
from .utils import ArgumentParser, format_time
|
from .utils import ArgumentParser, format_time
|
||||||
from syncplay import utils
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.protocol import ClientFactory
|
from twisted.internet.protocol import ClientFactory
|
||||||
import re
|
import re
|
||||||
import threading
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
class SyncClientProtocol(CommandProtocol):
|
class SyncClientProtocol(CommandProtocol):
|
||||||
@ -163,7 +161,6 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
def send_playing(self, filename):
|
def send_playing(self, filename):
|
||||||
self._protocol.sendMessage('playing', filename)
|
self._protocol.sendMessage('playing', filename)
|
||||||
|
|
||||||
|
|
||||||
class SyncClientFactory(ClientFactory):
|
class SyncClientFactory(ClientFactory):
|
||||||
def __init__(self, manager):
|
def __init__(self, manager):
|
||||||
self._syncplayClient = manager
|
self._syncplayClient = manager
|
||||||
@ -195,11 +192,8 @@ class SyncClientFactory(ClientFactory):
|
|||||||
def stop_retrying(self):
|
def stop_retrying(self):
|
||||||
self.retry = False
|
self.retry = False
|
||||||
|
|
||||||
|
class SyncplayClientManager(object):
|
||||||
class Manager(object):
|
def __init__(self, name, make_player, ui, debug):
|
||||||
def __init__(self, host, port, name, make_player, ui, debug):
|
|
||||||
self.host = host
|
|
||||||
self.port = port
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.ui = self.UiManager(ui, debug)
|
self.ui = self.UiManager(ui, debug)
|
||||||
@ -230,15 +224,12 @@ class Manager(object):
|
|||||||
|
|
||||||
self.make_player = make_player
|
self.make_player = make_player
|
||||||
self.running = False
|
self.running = False
|
||||||
command_handler = threading.Thread(target = utils.stdin_thread, args = (self,), name = "Command handler")
|
|
||||||
command_handler.setDaemon(True)
|
|
||||||
command_handler.start()
|
|
||||||
|
|
||||||
def start(self):
|
def start(self, host, port):
|
||||||
if self.running:
|
if self.running:
|
||||||
return
|
return
|
||||||
self.protocol_factory = SyncClientFactory(self)
|
self.protocol_factory = SyncClientFactory(self)
|
||||||
reactor.connectTCP(self.host, self.port, self.protocol_factory)
|
reactor.connectTCP(host, port, self.protocol_factory)
|
||||||
self.running = True
|
self.running = True
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,8 @@ class ConsoleUI(threading.Thread):
|
|||||||
self._syncplayClient = None
|
self._syncplayClient = None
|
||||||
threading.Thread.__init__(self, name="ConsoleUI")
|
threading.Thread.__init__(self, name="ConsoleUI")
|
||||||
|
|
||||||
def addManager(self, manager):
|
def addClient(self, client):
|
||||||
self._syncplayClient = manager
|
self._syncplayClient = client
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -90,7 +90,7 @@ class ConfigurationGetter(object):
|
|||||||
def _findWorkingDirectory(self):
|
def _findWorkingDirectory(self):
|
||||||
frozen = getattr(sys, 'frozen', '')
|
frozen = getattr(sys, 'frozen', '')
|
||||||
if not frozen:
|
if not frozen:
|
||||||
self._workingDir = os.path.dirname(__file__)
|
self._workingDir = os.path.dirname(os.path.dirname(__file__))
|
||||||
elif frozen in ('dll', 'console_exe', 'windows_exe'):
|
elif frozen in ('dll', 'console_exe', 'windows_exe'):
|
||||||
self._workingDir = os.path.dirname(sys.executable)
|
self._workingDir = os.path.dirname(sys.executable)
|
||||||
else:
|
else:
|
||||||
@ -115,7 +115,7 @@ class ConfigurationGetter(object):
|
|||||||
def _getSectionName(self):
|
def _getSectionName(self):
|
||||||
return 'sync' if not self._args.debug else 'debug'
|
return 'sync' if not self._args.debug else 'debug'
|
||||||
|
|
||||||
def _saveValuesIntoConfigFile(self):
|
def saveValuesIntoConfigFile(self):
|
||||||
self._openConfigFile()
|
self._openConfigFile()
|
||||||
section_name = self._getSectionName()
|
section_name = self._getSectionName()
|
||||||
if(not self._args.no_store):
|
if(not self._args.no_store):
|
||||||
@ -157,6 +157,7 @@ class ConfigurationGetter(object):
|
|||||||
self._prepareArgParser()
|
self._prepareArgParser()
|
||||||
self._args = self._parser.parse_args()
|
self._args = self._parser.parse_args()
|
||||||
self._readMissingValuesFromConfigFile()
|
self._readMissingValuesFromConfigFile()
|
||||||
|
self.saveValuesIntoConfigFile()
|
||||||
self._splitPortAndHost()
|
self._splitPortAndHost()
|
||||||
|
|
||||||
def getClientConfiguration(self):
|
def getClientConfiguration(self):
|
||||||
|
|||||||
@ -7,14 +7,15 @@ from syncplay import utils
|
|||||||
class SyncplayMPC:
|
class SyncplayMPC:
|
||||||
def runClient(self):
|
def runClient(self):
|
||||||
self._prepareArguments()
|
self._prepareArguments()
|
||||||
interface = ui.getUi(graphical = not self.args.no_gui)
|
self.interface = ui.getUi(graphical = not self.args.no_gui)
|
||||||
self._promptForMissingArguments()
|
self._promptForMissingArguments()
|
||||||
manager = client.Manager(self.args.host, self.args.port, self.args.name, lambda m: mpc.run_mpc(m, self.args.mpc_path, self.args.file, self.args._args), interface, self.args.debug)
|
syncplayClient = client.SyncplayClientManager(self.args.name, lambda m: mpc.run_mpc(m, self.args.mpc_path, self.args.file, self.args._args), self.interface, self.args.debug)
|
||||||
manager.start()
|
self.interface.addClient(syncplayClient)
|
||||||
|
syncplayClient.start(self.args.host, self.args.port)
|
||||||
def _prepareArguments(self):
|
def _prepareArguments(self):
|
||||||
args = utils.MPCConfigurationGetter()
|
self.argsGetter = utils.MPCConfigurationGetter()
|
||||||
args.prepareClientConfiguration()
|
self.argsGetter.prepareClientConfiguration()
|
||||||
self.args = args.getClientConfiguration()
|
self.args = self.argsGetter.getClientConfiguration()
|
||||||
|
|
||||||
def _promptForMissingArguments(self):
|
def _promptForMissingArguments(self):
|
||||||
if (self.args.host == None):
|
if (self.args.host == None):
|
||||||
@ -23,7 +24,7 @@ class SyncplayMPC:
|
|||||||
self.args.name = self.interface.promptFor(promptName = "Username", message = "You must supply username on the first run, it's easier trough command line arguments.")
|
self.args.name = self.interface.promptFor(promptName = "Username", message = "You must supply username on the first run, it's easier trough command line arguments.")
|
||||||
if (self.args.mpc_path == None):
|
if (self.args.mpc_path == None):
|
||||||
self.args.mpc_path = self.interface.promptFor(promptName = "Path to mpc-hc.exe", message = "You must supply path to mpc on the first run, it's easier trough command line arguments.")
|
self.args.mpc_path = self.interface.promptFor(promptName = "Path to mpc-hc.exe", message = "You must supply path to mpc on the first run, it's easier trough command line arguments.")
|
||||||
|
self.argsGetter.saveValuesIntoConfigFile()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
SyncplayMPC().runClient()
|
SyncplayMPC().runClient()
|
||||||
|
|||||||
@ -13,6 +13,6 @@ if __name__ == '__main__':
|
|||||||
args = prepareArguments()
|
args = prepareArguments()
|
||||||
args.args.extend(('-slave', '-msglevel', 'all=1:global=4'))
|
args.args.extend(('-slave', '-msglevel', 'all=1:global=4'))
|
||||||
if(args.file): args.args.extend((args.file,))
|
if(args.file): args.args.extend((args.file,))
|
||||||
manager = client.Manager(args.host, args.port, args.name, lambda m: mplayer.run_mplayer(m, 'mplayer', args.args))
|
manager = client.SyncplayClientManager(args.name, lambda m: mplayer.run_mplayer(m, 'mplayer', args.args))
|
||||||
manager.start()
|
manager.start(args.host, args.port)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user