bug fixes on refactoring

This commit is contained in:
Uriziel 2012-07-10 19:38:37 +02:00
parent 177821e170
commit 321fb5a3a5
5 changed files with 19 additions and 26 deletions

View File

@ -2,11 +2,9 @@
from .network_utils import argumentCount, CommandProtocol
from .utils import ArgumentParser, format_time
from syncplay import utils
from twisted.internet import reactor
from twisted.internet.protocol import ClientFactory
import re
import threading
import time
class SyncClientProtocol(CommandProtocol):
@ -163,7 +161,6 @@ class SyncClientProtocol(CommandProtocol):
def send_playing(self, filename):
self._protocol.sendMessage('playing', filename)
class SyncClientFactory(ClientFactory):
def __init__(self, manager):
self._syncplayClient = manager
@ -195,11 +192,8 @@ class SyncClientFactory(ClientFactory):
def stop_retrying(self):
self.retry = False
class Manager(object):
def __init__(self, host, port, name, make_player, ui, debug):
self.host = host
self.port = port
class SyncplayClientManager(object):
def __init__(self, name, make_player, ui, debug):
self.name = name
self.ui = self.UiManager(ui, debug)
@ -230,15 +224,12 @@ class Manager(object):
self.make_player = make_player
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:
return
self.protocol_factory = SyncClientFactory(self)
reactor.connectTCP(self.host, self.port, self.protocol_factory)
reactor.connectTCP(host, port, self.protocol_factory)
self.running = True
reactor.run()

View File

@ -15,8 +15,8 @@ class ConsoleUI(threading.Thread):
self._syncplayClient = None
threading.Thread.__init__(self, name="ConsoleUI")
def addManager(self, manager):
self._syncplayClient = manager
def addClient(self, client):
self._syncplayClient = client
def run(self):
try:

View File

@ -90,7 +90,7 @@ class ConfigurationGetter(object):
def _findWorkingDirectory(self):
frozen = getattr(sys, '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'):
self._workingDir = os.path.dirname(sys.executable)
else:
@ -115,7 +115,7 @@ class ConfigurationGetter(object):
def _getSectionName(self):
return 'sync' if not self._args.debug else 'debug'
def _saveValuesIntoConfigFile(self):
def saveValuesIntoConfigFile(self):
self._openConfigFile()
section_name = self._getSectionName()
if(not self._args.no_store):
@ -157,6 +157,7 @@ class ConfigurationGetter(object):
self._prepareArgParser()
self._args = self._parser.parse_args()
self._readMissingValuesFromConfigFile()
self.saveValuesIntoConfigFile()
self._splitPortAndHost()
def getClientConfiguration(self):

View File

@ -7,14 +7,15 @@ from syncplay import utils
class SyncplayMPC:
def runClient(self):
self._prepareArguments()
interface = ui.getUi(graphical = not self.args.no_gui)
self.interface = ui.getUi(graphical = not self.args.no_gui)
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)
manager.start()
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)
self.interface.addClient(syncplayClient)
syncplayClient.start(self.args.host, self.args.port)
def _prepareArguments(self):
args = utils.MPCConfigurationGetter()
args.prepareClientConfiguration()
self.args = args.getClientConfiguration()
self.argsGetter = utils.MPCConfigurationGetter()
self.argsGetter.prepareClientConfiguration()
self.args = self.argsGetter.getClientConfiguration()
def _promptForMissingArguments(self):
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.")
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.argsGetter.saveValuesIntoConfigFile()
if __name__ == '__main__':
SyncplayMPC().runClient()

View File

@ -13,6 +13,6 @@ if __name__ == '__main__':
args = prepareArguments()
args.args.extend(('-slave', '-msglevel', 'all=1:global=4'))
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.start()
manager = client.SyncplayClientManager(args.name, lambda m: mplayer.run_mplayer(m, 'mplayer', args.args))
manager.start(args.host, args.port)