added dependency checking
- Dependency install states will be checked and will be automatically installed if it isn't.
This commit is contained in:
		
							parent
							
								
									87bd857bfb
								
							
						
					
					
						commit
						32c837bfb2
					
				
					 1 changed files with 343 additions and 303 deletions
				
			
		
							
								
								
									
										64
									
								
								dance.py
									
										
									
									
									
								
							
							
						
						
									
										64
									
								
								dance.py
									
										
									
									
									
								
							|  | @ -1,3 +1,36 @@ | ||||||
|  | import os | ||||||
|  | 
 | ||||||
|  | def check_dependencies():  | ||||||
|  |     def check_dependency_aiohttp():  | ||||||
|  |         while True: | ||||||
|  |             try:  | ||||||
|  |                 import aiohttp | ||||||
|  |             except:  | ||||||
|  |                 os.system('pip3 install aiohttp==3.7.4') | ||||||
|  |             else:  | ||||||
|  |                 break | ||||||
|  | 
 | ||||||
|  |     def check_dependency_hidapi(): | ||||||
|  |         while True:  | ||||||
|  |             try:  | ||||||
|  |                 import hid | ||||||
|  |             except:  | ||||||
|  |                 os.system('pip3 install hidapi'); os.system('pip3 install hid') | ||||||
|  |             else:  | ||||||
|  |                 break | ||||||
|  | 
 | ||||||
|  |     def check_dependency_websockets(): | ||||||
|  |         while True:  | ||||||
|  |             try:  | ||||||
|  |                 import websockets | ||||||
|  |             except:  | ||||||
|  |                 os.system('pip3 install websockets') | ||||||
|  |             else:  | ||||||
|  |                 break | ||||||
|  |      | ||||||
|  |     check_dependency_aiohttp(); check_dependency_hidapi(); check_dependency_websockets() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| import asyncio | import asyncio | ||||||
| import json | import json | ||||||
| import logging | import logging | ||||||
|  | @ -13,14 +46,14 @@ import hid | ||||||
| from aiohttp import WSMsgType, web | from aiohttp import WSMsgType, web | ||||||
| 
 | 
 | ||||||
| from joydance import JoyDance, PairingState | from joydance import JoyDance, PairingState | ||||||
| from joydance.constants import (DEFAULT_CONFIG, JOYDANCE_VERSION, | from joydance.constants import (DEFAULT_CONFIG, JOYDANCE_VERSION, WsSubprotocolVersion) | ||||||
|                                 WsSubprotocolVersion) |  | ||||||
| from pycon import ButtonEventJoyCon, JoyCon | from pycon import ButtonEventJoyCon, JoyCon | ||||||
| from pycon.constants import JOYCON_PRODUCT_IDS, JOYCON_VENDOR_ID | from pycon.constants import JOYCON_PRODUCT_IDS, JOYCON_VENDOR_ID | ||||||
| 
 | 
 | ||||||
| logging.getLogger('asyncio').setLevel(logging.WARNING) | logging.getLogger('asyncio').setLevel(logging.WARNING) | ||||||
| 
 | 
 | ||||||
| 
 | def main():  | ||||||
|  |     try: | ||||||
|         class WsCommand(Enum): |         class WsCommand(Enum): | ||||||
|             GET_JOYCON_LIST = 'get_joycon_list' |             GET_JOYCON_LIST = 'get_joycon_list' | ||||||
|             CONNECT_JOYCON = 'connect_joycon' |             CONNECT_JOYCON = 'connect_joycon' | ||||||
|  | @ -260,24 +293,20 @@ def save_config(parser): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         async def on_startup(app): |         async def on_startup(app): | ||||||
|     print(''' |             os.system('clear') | ||||||
|      ░░  ░░░░░░  ░░    ░░ ░░░░░░   ░░░░░  ░░░    ░░  ░░░░░░ ░░░░░░░ |  | ||||||
|      ▒▒ ▒▒    ▒▒  ▒▒  ▒▒  ▒▒   ▒▒ ▒▒   ▒▒ ▒▒▒▒   ▒▒ ▒▒      ▒▒ |  | ||||||
|      ▒▒ ▒▒    ▒▒   ▒▒▒▒   ▒▒   ▒▒ ▒▒▒▒▒▒▒ ▒▒ ▒▒  ▒▒ ▒▒      ▒▒▒▒▒ |  | ||||||
| ▓▓   ▓▓ ▓▓    ▓▓    ▓▓    ▓▓   ▓▓ ▓▓   ▓▓ ▓▓  ▓▓ ▓▓ ▓▓      ▓▓ |  | ||||||
|  █████   ██████     ██    ██████  ██   ██ ██   ████  ██████ ███████ |  | ||||||
| 
 |  | ||||||
| Open http://localhost:32623 in your browser.''') |  | ||||||
| 
 | 
 | ||||||
|             # Check for update |             # Check for update | ||||||
|             async with aiohttp.ClientSession() as session: |             async with aiohttp.ClientSession() as session: | ||||||
|                 async with session.get('https://api.github.com/repos/redphx/joydance/releases/latest', ssl=False) as resp: |                 async with session.get('https://api.github.com/repos/redphx/joydance/releases/latest', ssl=False) as resp: | ||||||
|                     json_body = await resp.json() |                     json_body = await resp.json() | ||||||
|                     latest_version = json_body['tag_name'][1:] |                     latest_version = json_body['tag_name'][1:] | ||||||
|             print('Running version {}.'.format(JOYDANCE_VERSION)) |                     print('JoyDance V{}.'.format(JOYDANCE_VERSION)) | ||||||
|                     if JOYDANCE_VERSION != latest_version: |                     if JOYDANCE_VERSION != latest_version: | ||||||
|                         print('\033[93m{}\033[00m'.format('Version {} is available: https://github.com/redphx/joydance'.format(latest_version))) |                         print('\033[93m{}\033[00m'.format('Version {} is available: https://github.com/redphx/joydance'.format(latest_version))) | ||||||
|              |              | ||||||
|  |             time.sleep(2) | ||||||
|  |             os.system('open "http://localhost:32623"') | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|         async def html_handler(request): |         async def html_handler(request): | ||||||
|             config = dict((parse_config()).items('joydance')) |             config = dict((parse_config()).items('joydance')) | ||||||
|  | @ -343,3 +372,14 @@ app.add_routes([ | ||||||
|         ]) |         ]) | ||||||
| 
 | 
 | ||||||
|         web.run_app(app, port=32623) |         web.run_app(app, port=32623) | ||||||
|  |      | ||||||
|  |     except KeyboardInterrupt:  | ||||||
|  |         os.system('clear') | ||||||
|  |         return(0) | ||||||
|  |      | ||||||
|  |     except TypeError:  | ||||||
|  |         os.system('clear') | ||||||
|  |         return(0) | ||||||
|  | 
 | ||||||
|  | check_dependencies() | ||||||
|  | main() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue