-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_packages.py
More file actions
executable file
·101 lines (86 loc) · 3.34 KB
/
update_packages.py
File metadata and controls
executable file
·101 lines (86 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import annotations
from git.repo.base import Repo
import os
import shutil
import subprocess
CURRENT_DIR=os.path.dirname(os.path.realpath(__file__))
GIT_DIR=os.path.dirname(os.path.realpath(__file__))+"/git/"
SCRIPTS_DIR=os.path.dirname(os.path.realpath(__file__))+"/scripts/"
GENTOO_REPO_DIR=os.path.dirname(os.path.realpath(__file__))+"/gentoo_repository/"
LINUX_PATCHES_REPO_DIR=os.path.dirname(os.path.realpath(__file__))+"/linux-patches/"
import git
from alive_progress import alive_bar
class GitRemoteProgress(git.RemoteProgress):
OP_CODES = [
"BEGIN",
"CHECKING_OUT",
"COMPRESSING",
"COUNTING",
"END",
"FINDING_SOURCES",
"RECEIVING",
"RESOLVING",
"WRITING",
]
OP_CODE_MAP = {
getattr(git.RemoteProgress, _op_code): _op_code for _op_code in OP_CODES
}
def __init__(self) -> None:
super().__init__()
self.alive_bar_instance = None
@classmethod
def get_curr_op(cls, op_code: int) -> str:
"""Get OP name from OP code."""
# Remove BEGIN- and END-flag and get op name
op_code_masked = op_code & cls.OP_MASK
return cls.OP_CODE_MAP.get(op_code_masked, "?").title()
def update(
self,
op_code: int,
cur_count: str | float,
max_count: str | float | None = None,
message: str | None = "",
) -> None:
cur_count = float(cur_count)
max_count = float(max_count)
# Start new bar on each BEGIN-flag
if op_code & self.BEGIN:
self.curr_op = self.get_curr_op(op_code)
self._dispatch_bar(title=self.curr_op)
self.bar(cur_count / max_count)
self.bar.text(message)
# End progress monitoring on each END-flag
if op_code & git.RemoteProgress.END:
self._destroy_bar()
def _dispatch_bar(self, title: str | None = "") -> None:
"""Create a new progress bar"""
self.alive_bar_instance = alive_bar(manual=True, title=title)
self.bar = self.alive_bar_instance.__enter__()
def _destroy_bar(self) -> None:
"""Destroy an existing progress bar"""
self.alive_bar_instance.__exit__(None, None, None)
def save (source, directory):
if not os.path.exists(directory):
Repo.clone_from(source, directory, branch='master', progress=GitRemoteProgress())
else:
repo = Repo(directory)
repo.remotes[0].pull()
# download gentoo repository
save("git+ssh://git@git.gentoo.org/repo/gentoo.git", GENTOO_REPO_DIR)
# copy git configurations to gentoo repository
shutil.copyfile(GIT_DIR+'/gentoo_repository_config',GENTOO_REPO_DIR+"/.git/config")
# start packages updating scripts
os.system("python /opt/gentoo_dev/update_linux_patches.py")
os.system("python "+SCRIPTS_DIR+"rt_scraper.py")
os.system("python "+SCRIPTS_DIR+"vanilla_scraper.py")
os.system("python "+SCRIPTS_DIR+"git_scraper.py")
os.chdir(GENTOO_REPO_DIR)
git_not_yet_pushed_commits_short_logs=subprocess.getoutput("git log origin..HEAD")
git_not_yet_pushed_commits_detailed_logs=subprocess.getoutput("git log -p origin..HEAD")
os.chdir(CURRENT_DIR)
with open('commits/test_short', mode='w') as f:
f.write(git_not_yet_pushed_commits_short_logs)
with open('commits/test_long', mode='w') as f:
f.write(git_not_yet_pushed_commits_detailed_logs)