def setup_gui(): if is_linux(): print( "Before continuing with the GUI module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Linux-Installation-Guide#gui" ) elif is_macos(): print( "Before continuing with the GUI module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/macOS-Installation-Guide#gui" ) elif is_windows(): print( "Before continuing with the GUI module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Windows-Installation-Guide#gui" ) print("") input("Press Enter to continue...") if is_linux(): subprocess.call(shlex.split("pip install Kivy==1.10.0")) elif is_macos(): subprocess.call(shlex.split("pip install pygame Kivy==1.10.0")) elif is_windows(): subprocess.call( shlex.split( "pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew" )) subprocess.call(shlex.split("pip install Kivy==1.10.0")) print("") print("GUI module setup complete!")
def setup_dashboard(): if is_linux(): print( "Before continuing with the Dashboard module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Linux-Installation-Guide#dashboard" ) elif is_macos(): print( "Before continuing with the Dashboard module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/macOS-Installation-Guide#dashboard" ) elif is_windows(): print( "Before continuing with the Dashboard module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Windows-Installation-Guide#dashboard" ) print("") input("Press Enter to continue...") # Copy the base dashboard directory to the install location shutil.copytree( os.path.join(os.path.dirname(os.path.dirname(__file__)), "dashboard"), os.path.join(os.getcwd(), "dashboard")) # Copy the WAMP components to the install location dashboard directory shutil.copy( os.path.join(os.path.dirname(__file__), "wamp_components", "analytics_component.py"), os.path.join(os.getcwd(), "dashboard", "analytics_component.py")) shutil.copy( os.path.join(os.path.dirname(__file__), "wamp_components", "dashboard_api_component.py"), os.path.join(os.getcwd(), "dashboard", "dashboard_api_component.py")) # Install Kivy if is_linux(): subprocess.call(shlex.split("pip install Kivy==1.10.0")) elif is_macos(): subprocess.call(shlex.split("pip install pygame Kivy==1.10.0")) elif is_windows(): subprocess.call( shlex.split( "pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew" )) subprocess.call(shlex.split("pip install Kivy==1.10.0")) # Install CEFPython subprocess.call(shlex.split("pip install cefpython3==57.1")) # Install Pony ORM subprocess.call(shlex.split("pip install pony==0.7.3"))
def setup_ml(): if is_linux(): print( "Before continuing with the ML module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Linux-Installation-Guide#ml" ) elif is_macos(): print( "Before continuing with the ML module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/macOS-Installation-Guide#ml" ) elif is_windows(): print( "Before continuing with the ML module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Windows-Installation-Guide#ml" ) print("") input("Press Enter to continue...") # Decide on CPU or GPU Tensorflow tensorflow_backend = input( "\nWhich backend do you plan to use for Tensorflow (One of: 'CPU', 'GPU' - Note: GPU backend can only be used on NVIDIA GTX 600 series and up): \n" ) if tensorflow_backend not in ["CPU", "GPU"]: tensorflow_backend = "CPU" if tensorflow_backend == "GPU": subprocess.call(shlex.split("pip install tensorflow-gpu==1.5.1")) elif tensorflow_backend == "CPU": subprocess.call(shlex.split("pip install tensorflow==1.5.1")) subprocess.call(shlex.split("pip install Keras tensorforce==0.3.5.1")) print("") print("ML module setup complete!")
def _perform_retina_display_check(self): retina_display = False if is_macos(): frame = self.grab_frame() if frame.shape[0] > self.height: retina_display = True return retina_display
def _load_adapter(self): if is_linux(): from serpent.window_controllers.linux_window_controller import LinuxWindowController return LinuxWindowController elif is_macos(): from serpent.window_controllers.darwin_window_controller import DarwinWindowController return DarwinWindowController elif is_windows(): from serpent.window_controllers.win32_window_controller import Win32WindowController return Win32WindowController
def launch(self, **kwargs): url = kwargs.get("url") browser = kwargs.get("browser") or WebBrowser.DEFAULT if url is None: raise GameLauncherException("An 'url' kwarg is required...") if is_linux(): webbrowser.get(self.web_browsers.get(browser.name)).open_new(url) elif is_macos(): webbrowser.get(self.web_browsers.get(browser.name)).open_new(url) elif is_windows(): webbrowser.get(self.web_browsers.get(browser.name)).open_new(url)
def launch(self, **kwargs): executable_path = kwargs.get("executable_path") if executable_path is None: raise GameLauncherException( "An 'executable_path' kwarg is required...") if is_linux(): subprocess.Popen(shlex.split(executable_path)) elif is_macos(): subprocess.Popen(shlex.split(executable_path)) elif is_windows(): subprocess.Popen(executable_path)
def update(): clear_terminal() display_serpent_logo() print("") print("Updating Serpent.AI to the latest version...") subprocess.call(shlex.split("pip install --upgrade SerpentAI")) if is_linux(): shutil.copy( os.path.join(os.path.dirname(__file__), "requirements.linux.txt"), os.path.join(os.getcwd(), "requirements.txt")) elif is_macos(): shutil.copy( os.path.join(os.path.dirname(__file__), "requirements.darwin.txt"), os.path.join(os.getcwd(), "requirements.txt")) elif is_windows(): shutil.copy( os.path.join(os.path.dirname(__file__), "requirements.win32.txt"), os.path.join(os.getcwd(), "requirements.txt")) subprocess.call(shlex.split("pip install -r requirements.txt")) import yaml with open(os.path.join(os.path.dirname(__file__), "config", "config.yml"), "r") as f: serpent_config = yaml.safe_load(f) or {} with open(os.path.join(os.getcwd(), "config", "config.yml"), "r") as f: user_config = yaml.safe_load(f) or {} config_changed = False for key, value in serpent_config.items(): if key not in user_config: user_config[key] = value config_changed = True if config_changed: with open(os.path.join(os.getcwd(), "config", "config.yml"), "w") as f: f.write(yaml.dump(user_config))
def launch(self, **kwargs): app_id = kwargs.get("app_id") app_args = kwargs.get("app_args") if app_id is None: raise GameLauncherException("An 'app_id' kwarg is required...") protocol_string = f"steam://run/{app_id}" if app_args is not None: args_list = [f"--{k}={v}" for k, v in app_args.items()] protocol_string += "/en/" + " ".join(args_list) if is_linux(): subprocess.call(shlex.split(f"xdg-open '{protocol_string}'")) elif is_macos(): subprocess.call(shlex.split(f"open '{protocol_string}'")) elif is_windows(): webbrowser.open(f"{protocol_string}")
def launch(self, **kwargs): executable_path = kwargs.get("executable_path") current_work_directory = kwargs.get("current_work_directory") print("executable_path", executable_path, "current_work_directory", current_work_directory) print("shlex.split(executable_path):", shlex.quote(executable_path)) if executable_path is None: raise GameLauncherException( "An 'executable_path' kwarg is required...") if is_linux(): subprocess.Popen(shlex.quote(executable_path), cwd=current_work_directory) elif is_macos(): subprocess.Popen(shlex.quote(executable_path), cwd=current_work_directory) elif is_windows(): subprocess.Popen(shlex.quote(executable_path), cwd=current_work_directory)
def setup_ocr(): if is_linux(): print( "Before continuing with the OCR module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Linux-Installation-Guide#ocr" ) elif is_macos(): print( "Before continuing with the OCR module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/macOS-Installation-Guide#ocr" ) elif is_windows(): print( "Before continuing with the OCR module setup, please read and perform the installation steps from the wiki: https://github.com/SerpentAI/SerpentAI/wiki/Windows-Installation-Guide#ocr" ) print("") input("Press Enter to continue...") if is_unix(): subprocess.call(shlex.split("pip install tesserocr")) elif is_windows(): subprocess.call(shlex.split("pip install pytesseract")) print("") print("OCR module setup complete!")
def setup_base(): # Copy Config Templates print("Creating Configuration Files...") first_run = True for root, directories, files in os.walk(os.getcwd()): for file in files: if file == "offshoot.yml": first_run = False break if not first_run: break if not first_run: confirm = input( "It appears that the setup process had already been performed. Are you sure you want to proceed? Some important files will be overwritten! (One of: 'YES', 'NO'):\n" ) if confirm not in ["YES", "NO"]: confirm = "NO" if confirm == "NO": sys.exit() shutil.rmtree(os.path.join(os.getcwd(), "config"), ignore_errors=True) shutil.copytree(os.path.join(os.path.dirname(__file__), "config"), os.path.join(os.getcwd(), "config")) # Copy Offshoot Files shutil.copy(os.path.join(os.path.dirname(__file__), "offshoot.yml"), os.path.join(os.getcwd(), "offshoot.yml")) shutil.copy( os.path.join(os.path.dirname(__file__), "offshoot.manifest.json"), os.path.join(os.getcwd(), "offshoot.manifest.json")) # Generate Platform-Specific requirements.txt if is_linux(): shutil.copy( os.path.join(os.path.dirname(__file__), "requirements.linux.txt"), os.path.join(os.getcwd(), "requirements.txt")) elif is_macos(): shutil.copy( os.path.join(os.path.dirname(__file__), "requirements.darwin.txt"), os.path.join(os.getcwd(), "requirements.txt")) elif is_windows(): shutil.copy( os.path.join(os.path.dirname(__file__), "requirements.win32.txt"), os.path.join(os.getcwd(), "requirements.txt")) # Install the dependencies print("Installing dependencies...") if is_linux(): subprocess.call(shlex.split("pip install python-xlib")) elif is_macos(): subprocess.call( shlex.split( "pip install python-xlib pyobjc-framework-Quartz py-applescript" )) elif is_windows(): # Anaconda Packages subprocess.call(shlex.split( "conda install numpy scipy scikit-image scikit-learn h5py -y"), shell=True) subprocess.call(shlex.split("pip install -r requirements.txt")) # Install Crossbar subprocess.call(shlex.split("pip install crossbar==18.6.1")) # Create Dataset Directories os.makedirs(os.path.join(os.getcwd(), "datasets/collect_frames"), exist_ok=True) os.makedirs(os.path.join(os.getcwd(), "datasets/collect_frames_for_context"), exist_ok=True) os.makedirs(os.path.join(os.getcwd(), "datasets/current"), exist_ok=True) # Copy the Crossbar config shutil.copy(os.path.join(os.path.dirname(__file__), "crossbar.json"), os.path.join(os.getcwd(), "crossbar.json"))