Verified Commit 08f6978c authored by Oskar Roesler's avatar Oskar Roesler
Browse files

Refactor general.py and add support for storing files under...

Refactor general.py and add support for storing files under ~/.config/ros-aur-helper and ~/.cache/ros-aur-helper
parent 59d66b24
......@@ -10,7 +10,7 @@ class Clone(Routines):
self.url = "git@github.com:{0}/{1}.git".format(self.gh_organization_name, self.package)
def cloning(self):
Repo.clone_from(self.url, self.path)
Repo.clone_from(self.url, self.repos_path)
def clone(self):
if self.package=="all":
......@@ -30,7 +30,7 @@ class Pull(Routines):
for folder in os.listdir("./packages"):
t.submit(Pull(folder, self.verbosity, self.output).pull)
else:
repo = Repo(path=self.path)
repo = Repo(path=self.repos_path)
repo.git.stash()
repo.git.stash("clear")
head_before = repo.head.object.hexsha
......
......@@ -12,10 +12,10 @@ class Packages(Routines):
CHROOT = os.environ.get('CHROOT')
def makepkg(self):
if os.path.isfile(os.path.join(self.path, "PKGBUILD")):
if os.path.isfile(os.path.join(self.repos_path, "PKGBUILD")):
try:
subprocess.run(['makechrootpkg', '-c', '-r', self.CHROOT], stdout=( None if self.verbosity else subprocess.DEVNULL), \
stderr=subprocess.STDOUT, cwd=self.path, check=True)
stderr=subprocess.STDOUT, cwd=self.repos_path, check=True)
with open("success.txt", "a") as fobj:
fobj.write(self.package + "\n")
if self.output:
......@@ -26,7 +26,7 @@ class Packages(Routines):
fobj.write(self.package + "\n")
raise RuntimeWarning("Building of {0} failed".format(self.package))
else:
raise FileNotFoundError("No PKBUILD existing: ", self.path)
raise FileNotFoundError("No PKBUILD existing: ", self.repos_path)
def build(self):
if self.package=="all":
......@@ -40,14 +40,14 @@ class Packages(Routines):
os.remove(pkg)
def mvpkg(self):
for pkg_path in glob.iglob(self.path + "/*pkg.tar*"):
for pkg_path in glob.iglob(self.repos_path + "/*pkg.tar*"):
shutil.move(pkg_path, "./repository/")
def aur_push(self):
try:
pkg_repo = Repo(path=self.path).remote(name='aur')
pkg_repo = Repo(path=self.repos_path).remote(name='aur')
except ValueError:
pkg_repo = Repo(path=self.path).create_remote('aur', "aur@aur.archlinux.org:/{0}.git".format(self.package))
pkg_repo = Repo(path=self.repos_path).create_remote('aur', "aur@aur.archlinux.org:/{0}.git".format(self.package))
pkg_repo.fetch()
try:
pkg_repo.push()
......
......@@ -16,19 +16,28 @@ class Routines:
self.package = package
self.verbosity = verbosity
self.output = output
self.path = os.path.join("./packages/{0}".format(self.package))
config = Routines.get_config()
self.config_path = os.path.join(Routines.CONFIG_ROOT, 'ros-aur-helper')
self.cache_path = os.path.join(Routines.CACHE_ROOT, 'ros-aur-helper')
self.check_and_create_path(self.config_path)
self.check_and_create_path(self.cache_path)
self.repos_path = os.path.join(self.cache_path, "packages", self.package)
config = self.get_config()
self.gh = Github(config['CI']['GH_OAUTH_TOKEN'])
self.gh_organization_name = config['CI']['GH_ORGANIZATION']
self.gh_organization = self.gh.get_organization(self.gh_organization_name)
@staticmethod
def get_config():
config_path = os.path.join(Routines.CONFIG_ROOT, 'ros-aur-helper', 'config.ini')
if not os.path.exists(config_path):
shutil.copy('config_example.ini', config_path)
def check_and_create_path(path):
if not (os.path.exists(path)):
Path.mkdir(path)
def get_config(self):
configfile_path = os.path.join(self.config_path, 'config.ini')
if not os.path.exists(configfile_path):
shutil.copy('config_example.ini', configfile_path)
config = configparser.ConfigParser()
config.read(config_path)
config.read(configfile_path)
return config
def delete_package_line(self, file):
......@@ -67,9 +76,8 @@ class Routines:
'pkgname': pkgname, 'src': src, 'pkgver': pkgver, 'dl': dl, 'url': url}
return ros_dict
@staticmethod
def get_ros_distro():
config = Routines.get_config()
def get_ros_distro(self):
config = self.get_config()
return config['CI']['GH_ORGANIZATION'].rstrip("arch")
@staticmethod
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment