Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from sathya-pramodh/testing
Browse files Browse the repository at this point in the history
Distributing the package with pip now. Some bugs have been corrected.
  • Loading branch information
sathya-pramodh authored Jun 28, 2022
2 parents bf88c13 + 85c2e38 commit f4a04b4
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 75 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
log/
config.py
__pycache__/*
dist/*
66 changes: 14 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Multi Instance Macro Handler for Minecraft on Linux.
- Wall support.
- OBS integration for Wall Resetting.
- Full keyboard support.
- Distributed through pip for easy installation.
- An "almost" drop-in repleacement on Linux for [Specnr's macro designed for Windows](https://github.com/Specnr/MultiResetWall)

# Dependencies
Expand All @@ -18,49 +19,21 @@ Multi Instance Macro Handler for Minecraft on Linux.
- [OBS websocket plugin](https://github.com/obsproject/obs-websocket)

# Installation
### keyboard
- Install pip on your system first to install this dependency.
```
sudo pip install keyboard
```
### wmctrl
- Debian/Debian-based distros
```
sudo apt update
sudo apt install wmctrl
```
- Arch/Arch-based distros
```
sudo pacman -Sy
sudo pacman -S wmctrl
```
- RHEL/RHEL-based distros
```
sudo dnf upgrade
sudo dnf intall wmctrl
```
### xdotool
- Debian/Debian-based distros
## Dependencies
- Debian/Debian-based distros
```
sudo apt update
sudo apt install xdotool
sudo apt install wmctrl xdotool
```
- Arch/Arch-based distros
```
sudo pacman -Sy
sudo pacman -S xdotool
sudo pacman -S wmctrl xdotool
```
- RHEL/RHEL-based distros
```
sudo dnf upgrade
sudo dnf install xdotool
```

### obs-websocket-py
- Download this if and only if you plan on using wall.

```
sudo pip install obs-websocket-py
sudo dnf install wmctrl xdotool
```

### OBS websocket plugin
Expand All @@ -79,30 +52,19 @@ yay -S obs-websocket
- Note: The script was tested on 'obs-studio-tytan652' available on the AUR (Arch User Repositories).
- Any bugs on other versions can be posted in the [Issues](https://github.com/sathya-pramodh/MultiInstanceLinux/issues) tab.

## Download the latest release from the releases page

## Extract the .zip or .tar.gz file and then follow the usage instructions

## Make the startup script executable
```
chmod +x start.sh
```

## Dev Instructions
- Clone this repository
```
git clone https://github.com/sathya-pramodh/MultiInstanceLinux
cd MultiInstanceLinux/
```
- Update your local repository
### Install the package from pip
- Install the package distributed through pip.
- Use sudo to install the package as pip by default installs packages in `.local/` directory which is usually not in PATH for many distros.
- By using sudo, it installs the package in `/usr/` which is in PATH by default.
```
git pull origin main
sudo pip install MultiInstanceLinux
```

# Usage
- This command must be executed in a terminal each time you want to use the macro. You could set it up so that the script runs each time you start up all the instances of Minecraft.
- It must be executed with sudo because the keyboard module requires elevated privileges to run on Linux.
```
./start.sh
sudo multiinstancelinux
```

## Some important instructions
Expand Down Expand Up @@ -142,7 +104,7 @@ git pull origin main
- `Shift+9` - Switch to Instance 9 and reset all others.

# Configuration
- All configurations can be done in config.py
- All configurations can be done in config.py which is located in the .config/MultiInstanceLinux/ directory of your home folder.
- A default config is provided and the script will rollback to it if it doesn't find the file in the working directory.
- A new config.py will be created from the default config if a config.py doesn't exist already.

Expand Down
32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from setuptools import setup

def get_long_description():
with open("README.md", "r") as file:
long_description = file.read()
return long_description

setup(
name="MultiInstanceLinux",
version="1.2.7",
author="sathya-pramodh",
author_email="sathyapramodh17@gmail.com",
description="Multi Instance Macro Handler for Minecraft on Linux.",
long_description=get_long_description(),
long_description_content_type="text/markdown",
url="https://github.com/sathya-pramodh/MultiInstanceLinux",
project_urls={
"Bug Tracker": "https://github.com/sathya-pramodh/MultiInstanceLinux/issues",
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
],
python_requires=">=3.7",
install_requires=["keyboard", "obs-websocket-py"],
entry_points={
"console_scripts": [
"multiinstancelinux = MultiInstanceLinux.__init__:main",
]
},
package_data={'MultiInstanceLinux':['src/MultiInstanceLinux/default_config.py']},
)
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MultiInstanceLinux.egg-info/*
6 changes: 6 additions & 0 deletions src/MultiInstanceLinux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
log/
config.py
13 changes: 13 additions & 0 deletions src/MultiInstanceLinux/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os
import sys

def main():
"""
Main function to call the multi instance macro handler.
Returns 0 if the script execution was successful else 1.
"""
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.append(project_root)
from multi_instance import main
return main(project_root)
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 57 additions & 10 deletions multi_instance.py → src/MultiInstanceLinux/multi_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
# Imports
import os
import time
import sys
import keyboard
import macro_handlers.instance_handlers as switch_macro
import macro_handlers.reset_handlers as reset_macro
import macro_handlers.suspend_handlers as suspend_macro
import macro_handlers.wall_handlers as wall_macro
import config
import subprocess
from helper_scripts.logging import Logging

Expand Down Expand Up @@ -329,6 +329,11 @@ def handle_keybinds(hex_codes, obs_hex_code, pids):
Returns None if the script executed successfully, else -1 for any errors.
"""
using_wall = config.USING_WALL
config.INSTANCE_SCENE_NAMES = config.INSTANCE_SCENE_NAMES[: len(hex_codes)]
config.SWITCH_INSTANCES = config.SWITCH_INSTANCES[: len(hex_codes)]
config.SWITCH_AND_RESET_INSTANCES = config.SWITCH_AND_RESET_INSTANCES[
: len(hex_codes)
]
while True:
(
switched_to_instance_without_resetting,
Expand Down Expand Up @@ -361,9 +366,9 @@ def handle_keybinds(hex_codes, obs_hex_code, pids):
return -1


def main():
def start():
"""
The main function to be called for the execution of the script.
The function to be called to start the macro
Returns 0 if the script was executed successfully else -1 for any configuration error.
"""
Expand All @@ -384,14 +389,56 @@ def main():
return 0


# Checking if the script has been imported from an external script.
if __name__ == "__main__":
def get_config(project_root, config_dir):
"""
The function to copy the default configuration file to the user's config directory.
project_root
The root directory of the project represented as a string.
config_dir
The .config directory of the user represented as a string.
Returns None.
"""
config_file = project_root + "/default_config.py"
target_file = config_dir + "/MultiInstanceLinux/config.py"
os.system("cp {} {}".format(config_file, target_file))


def main(project_root):
"""
The main function to be called to startup the script.
project_root
The directory of the project root represented as a string.
Returns None.
"""
script_start_time = time.time()
WORKING_DIRECTORY = os.getcwd()
if not os.path.isdir("{}/log/".format(WORKING_DIRECTORY)):
os.mkdir("{}/log/".format(WORKING_DIRECTORY))
logger = Logging("{}/log/".format(WORKING_DIRECTORY))
return_code = main()
username = os.environ.get("SUDO_USER", os.environ.get("USERNAME"))
if username is None:
print(
"Not a sudo user or no sudo user has logged in. Execute the script with sudo previleges. Exitting the script..."
)
return -1
home = os.path.expanduser("~{}".format(username))
config_dir = home + "/.config"
log_dir = home + "/.config/MultiInstanceLinux"
if not os.path.isdir("{}/logs/".format(log_dir)):
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
os.mkdir("{}/logs/".format(log_dir))
global logger
logger = Logging("{}/logs/".format(log_dir))
sys.path.append(log_dir)
if not os.path.isfile(config_dir + "/MultiInstanceLinux/config.py"):
get_config(project_root, config_dir)
global config
import config

os.chdir(project_root)
return_code = start()

if return_code == 0:
script_end_time = time.time()
Expand Down
7 changes: 0 additions & 7 deletions start.sh

This file was deleted.

0 comments on commit f4a04b4

Please sign in to comment.