Skip to content

Commit

Permalink
trying to fix updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Avinash Reddy committed Dec 16, 2019
1 parent 334deb6 commit fcb7acb
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions userbot/modules/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from userbot import CMD_HELP, bot, HEROKU_MEMEZ, HEROKU_APIKEY, HEROKU_APPNAME, UPSTREAM_REPO_URL
from userbot.events import register

basedir = path.abspath(path.curdir)
requirements_path = path.join(
path.dirname(path.dirname(path.dirname(__file__))), 'requirements.txt')

Expand All @@ -31,6 +30,11 @@ async def gen_chlog(repo, diff):
return ch_log


async def initial_git(repo):
update = repo.create_remote('master', UPSTREAM_REPO_URL)
update.pull('master')


async def update_requirements():
reqs = str(requirements_path)
try:
Expand All @@ -52,33 +56,28 @@ async def upstream(ups):

try:
txt = "`Oops.. Updater cannot continue due to some problems occured`\n\n**LOGTRACE:**\n"
repo = Repo(basedir)
repo = Repo()
except NoSuchPathError as error:
await ups.edit(f'{txt}\n`directory {error} is not found`')
repo.__del__()
return
except GitCommandError as error:
await ups.edit(f'{txt}\n`Early failure! {error}`')
repo.__del__()
return
except InvalidGitRepositoryError as error:
repo = Repo.init()
if conf != "now":
await ups.edit(
f'`[WARNING] Directory {error} does not seems to be a git repository.\
\nTry force-updating the userbot using .update now.`')
return
try:
await ups.edit(
f'`[WARNING] Force-Syncing latest stable codebase, please wait..`'
)
await initial_git(repo)
except Exception as err:
await ups.edit(f'{txt}\n`{err}`')
return
if path.exists(f"{basedir}\.git"):
repo = Repo.init(basedir)
repo.git.fetch(UPSTREAM_REPO_URL)
repo_worker.git.reset('--hard')
repo_worker.git.clean('-fdx')
else:
rmtree(basedir, ignore_errors=True)
try:
makedirs(basedir)
except FileExistsError:
pass
Repo.clone_from(UPSTREAM_REPO_URL, basedir)
reqs_upgrade = await update_requirements()
await ups.edit(
'`Updated succesfully, check the commit history for changelog.\n'
Expand Down Expand Up @@ -112,16 +111,13 @@ async def upstream(ups):
await ups.edit(
f'`[WARNING] Force-Syncing latest stable codebase, please wait..`'
)
origin = repo.create_remote('master', UPSTREAM_REPO_URL)
repo.git.reset('--hard')
origin.pull('master')
await initial_git(repo)
reqs_upgrade = await update_requirements()
await ups.edit(
'`Updated succesfully, check the commit history for changelog.\n'
'Bot is restarting... Wait for a while!`')
except Exception as error:
await ups.edit(f"{txt}\n`Here's the error log: {error}`")
repo.__del__()
return
await bot.disconnect()
# Spin a new instance of bot
Expand Down Expand Up @@ -197,13 +193,15 @@ async def upstream(ups):
force=True)
except GitCommandError as error:
await ups.edit(f"{txt}\n`Here's the error log: {error}`")
repo.__del__()

else:
ups_rem.fetch(ac_br)
repo.git.reset('--hard')
try:
ups_rem.pull(ac_br)
except GitCommandError:
repo.git.reset('--hard')
reqs_upgrade = await update_requirements()
await ups.edit('`Successfully Updated!\n'
'Bot is restarting... Wait for a while!`')
await ups.edit(
'`Successfully Updated!\nBot is restarting... Wait for a while!`')
await bot.disconnect()
# Spin a new instance of bot
args = [sys.executable, "-m", "userbot"]
Expand Down

0 comments on commit fcb7acb

Please sign in to comment.