aboutsummaryrefslogtreecommitdiff
path: root/pomu
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-05-30 11:15:05 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-05-30 11:15:05 +0300
commitbe5b3ffe3df29a58975dbf636069e4b18784d4c5 (patch)
tree183362ba83e94d7bf8ca0bcab14e23ae512a7a7e /pomu
parentAdd GitPython import (diff)
downloadpomu-be5b3ffe3df29a58975dbf636069e4b18784d4c5.tar.gz
pomu-be5b3ffe3df29a58975dbf636069e4b18784d4c5.tar.bz2
pomu-be5b3ffe3df29a58975dbf636069e4b18784d4c5.zip
Refactor pomu initialization
Clean up created directory on initialization failure
Diffstat (limited to 'pomu')
-rw-r--r--pomu/pomu.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/pomu/pomu.py b/pomu/pomu.py
index 63f2ee1..6ca27b8 100644
--- a/pomu/pomu.py
+++ b/pomu/pomu.py
@@ -1,6 +1,7 @@
import click
import portage
from git import Repo
+from shutil import rmtree
from portage.os import path, makedirs
#TODO: global --repo option, (env var?)
@@ -33,7 +34,6 @@ def init(list_repos, create, repo, repo_dir):
print('Error: a repository with such name already exists!')
return
repo_path = path.join(repo_dir, repo)
- pomu_path = path.join(repo_path, 'metadata', 'pomu')
try:
makedirs(repo_path)
except PermissionError:
@@ -45,36 +45,36 @@ def init(list_repos, create, repo, repo_dir):
f.write('location = ' + repo_path + '\n')
except PermissionError:
print('Error: you do not have enough permissions to setup a portage repo')
- # TODO: cleanup the dir
+ rmtree(repo_path)
return
r = Repo.init(repo_path)
- makedirs(pomu_path)
- open(path.join(pomu_path, '.sentinel'), 'w').close()
- r.index.add(pomu_path)
- r.index.commit('Initialized pomu')
- print('Initialized repository', repo, 'successfully')
+ if not pomu_init(repo_path):
+ rmtree(repo_path)
else:
if repo not in rs.prepos_order:
print('Error: repository not found')
return
- repo_path = rs.prepos[repo]
+ init_pomu(rs.prepos[repo])
+
+def init_pomu(repo_path):
pomu_path = path.join(repo_path, 'metadata', 'pomu')
if not path.isdir(path.join(repo_path, '.git')):
print('Error: target repository should be a git repo')
- return
+ return False
if path.isdir(pomu_path):
print('Repository', repo, 'already initialized')
- return
+ return True
r = Repo(repo_path)
try:
makedirs(pomu_path)
open(path.join(pomu_path, '.sentinel'), 'w').close()
except PermissionError:
print('Error: you do not have enough permissions to modify the repo')
- return
+ return False
r.index.add(pomu_path)
r.index.commit('Initialized pomu')
print('Initialized repository', repo, 'successfully')
+ return True
@main.command()
def status():