Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…UserBot into modular
  • Loading branch information
baalajimaestro committed Jan 19, 2019
2 parents 240c701 + adcf5b8 commit b4fe627
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
neofetch
2 changes: 1 addition & 1 deletion userbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import subprocess
import sys, os
import dotenv

dotenv.load_dotenv("config.env")
BUILD_CHOICE=os.environ.get("BUILD_CHOICE","stable")
subprocess.run(["rm", "-rf", "brains.check"], stdout=subprocess.PIPE)
Expand Down Expand Up @@ -107,6 +106,7 @@
DB_URI = os.environ.get("DB_URI", None)
SCREEN_SHOT_LAYER_ACCESS_KEY = os.environ.get("SCREEN_SHOT_LAYER_ACCESS_KEY", None)
OPEN_WEATHER_MAP_APPID = os.environ.get("OPEN_WEATHER_MAP_APPID", None)
SUDO = os.environ.get("SUDO", None)
if CONSOLE_LOGGER_VERBOSE:
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
Expand Down
45 changes: 45 additions & 0 deletions userbot/modules/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import subprocess
import platform
from userbot import SUDO

def _start_instalation():
install_with = None
package_managers = ["pacman", "apt-get", "yum", "brew", "yaourt", "dnf", "homebrew", "eopkg", "snap"]
if "linux" in str(platform.system()).lower():
for manager in package_managers:
try:
subprocess.check_call(f"which {manager}", shell=True, stderr=subprocess.STDOUT)
install_package(manager)
return
except:
continue



def install_package(package_manager):
packages = []
to_install = []
with open("Aptfile") as file:
for line in file:
packages.append(line)

for package in packages:
try:
subprocess.check_call(f"which {package}", shell=True, stderr=subprocess.STDOUT)
except:
to_install.append(package)

if to_install:
if SUDO:
subprocess.Popen(f"echo {str(SUDO)} | sudo -S {str(package_manager)}" +
f" install -y {' '.join(to_install)}", shell=True)
else:
subprocess.Popen(f"{str(package_manager)} install -y {' '.join(to_install)}",
shell=True)

try:
if not 'heroku' in os.environ['PATH']:
_start_instalation()
except:
_start_instalation()

0 comments on commit b4fe627

Please sign in to comment.