diff --git a/.gitignore b/.gitignore index 95fe6f5..298a39b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ *.exe venv -/SyncPlay.egg-info +/*.egg-info /build /cert /dist diff --git a/setup.py b/setup.py index 7770fb0..411388f 100644 --- a/setup.py +++ b/setup.py @@ -28,11 +28,19 @@ setuptools.setup( long_description_content_type="text/markdown", url="https://www.syncplay.pl", packages=setuptools.find_packages(), - install_requires=["twisted", "pyside2", "requests", 'zope.inteface; platform_system=="Windows"', - 'pypiwin32; platform_system=="Windows"', 'appnope; platform_system=="Darwin"' + install_requires=["twisted", "pyside2", 'zope.inteface; platform_system=="Windows"', + 'pypiwin32; platform_system=="Windows"', 'appnope; platform_system=="Darwin"', + 'requests; platform_system=="Darwin"' ], python_requires=">=3.4", - scripts=['syncplayClient.py', 'syncplayServer.py'], + entry_points={ + 'console_scripts': [ + 'syncplay-server = syncplay.ep_server:main', + ], + 'gui_scripts': [ + 'syncplay = syncplay.ep_client:main', + ] + }, include_package_data=True, classifiers=[ "Development Status :: 5 - Production/Stable", diff --git a/syncplay/ep_client.py b/syncplay/ep_client.py new file mode 100644 index 0000000..f93793b --- /dev/null +++ b/syncplay/ep_client.py @@ -0,0 +1,11 @@ +import sys + +from syncplay.clientManager import SyncplayClientManager +from syncplay.utils import blackholeStdoutForFrozenWindow + +def main(): + blackholeStdoutForFrozenWindow() + SyncplayClientManager().run() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/syncplay/ep_server.py b/syncplay/ep_server.py new file mode 100644 index 0000000..7bb899e --- /dev/null +++ b/syncplay/ep_server.py @@ -0,0 +1,58 @@ +import socket +import sys + +from twisted.internet import reactor +from twisted.internet.endpoints import TCP4ServerEndpoint, TCP6ServerEndpoint +from twisted.internet.error import CannotListenError + +from syncplay.server import SyncFactory, ConfigurationGetter + +class ServerStatus: pass + +def isListening6(f): + ServerStatus.listening6 = True + +def isListening4(f): + ServerStatus.listening4 = True + +def failed6(f): + ServerStatus.listening6 = False + print(f.value) + print("IPv6 listening failed.") + +def failed4(f): + ServerStatus.listening4 = False + if f.type is CannotListenError and ServerStatus.listening6: + pass + else: + print(f.value) + print("IPv4 listening failed.") + +def main(): + argsGetter = ConfigurationGetter() + args = argsGetter.getConfiguration() + factory = SyncFactory( + args.port, + args.password, + args.motd_file, + args.isolate_rooms, + args.salt, + args.disable_ready, + args.disable_chat, + args.max_chat_message_length, + args.max_username_length, + args.stats_db_file, + args.tls + ) + endpoint6 = TCP6ServerEndpoint(reactor, int(args.port)) + endpoint6.listen(factory).addCallbacks(isListening6, failed6) + endpoint4 = TCP4ServerEndpoint(reactor, int(args.port)) + endpoint4.listen(factory).addCallbacks(isListening4, failed4) + if ServerStatus.listening6 or ServerStatus.listening4: + reactor.run() + else: + print("Unable to listen using either IPv4 and IPv6 protocols. Quitting the server now.") + sys.exit() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/syncplayClient.py b/syncplayClient.py index dad7ac3..2f40d78 100755 --- a/syncplayClient.py +++ b/syncplayClient.py @@ -11,9 +11,7 @@ except AttributeError: import warnings warnings.warn("You must run Syncplay with Python 3.4 or newer!") -from syncplay.clientManager import SyncplayClientManager -from syncplay.utils import blackholeStdoutForFrozenWindow +from syncplay import ep_client if __name__ == '__main__': - blackholeStdoutForFrozenWindow() - SyncplayClientManager().run() + ep_client.main() \ No newline at end of file diff --git a/syncplayServer.py b/syncplayServer.py index b0538d3..369714f 100755 --- a/syncplayServer.py +++ b/syncplayServer.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 #coding:utf8 -import socket import sys # libpath @@ -13,56 +12,7 @@ except AttributeError: import warnings warnings.warn("You must run Syncplay with Python 3.4 or newer!") -from twisted.internet import reactor -from twisted.internet.endpoints import TCP4ServerEndpoint, TCP6ServerEndpoint -from twisted.internet.error import CannotListenError - -from syncplay.server import SyncFactory, ConfigurationGetter - -class ServerStatus: pass - -def isListening6(f): - ServerStatus.listening6 = True - -def isListening4(f): - ServerStatus.listening4 = True - -def failed6(f): - ServerStatus.listening6 = False - print(f.value) - print("IPv6 listening failed.") - -def failed4(f): - ServerStatus.listening4 = False - if f.type is CannotListenError and ServerStatus.listening6: - pass - else: - print(f.value) - print("IPv4 listening failed.") - +from syncplay import ep_server if __name__ == '__main__': - argsGetter = ConfigurationGetter() - args = argsGetter.getConfiguration() - factory = SyncFactory( - args.port, - args.password, - args.motd_file, - args.isolate_rooms, - args.salt, - args.disable_ready, - args.disable_chat, - args.max_chat_message_length, - args.max_username_length, - args.stats_db_file, - args.tls - ) - endpoint6 = TCP6ServerEndpoint(reactor, int(args.port)) - endpoint6.listen(factory).addCallbacks(isListening6, failed6) - endpoint4 = TCP4ServerEndpoint(reactor, int(args.port)) - endpoint4.listen(factory).addCallbacks(isListening4, failed4) - if ServerStatus.listening6 or ServerStatus.listening4: - reactor.run() - else: - print("Unable to listen using either IPv4 and IPv6 protocols. Quitting the server now.") - sys.exit() + ep_server.main() \ No newline at end of file