Skip to content

Commit

Permalink
githubplugin: webif, install working
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Nov 6, 2024
1 parent 9b19be0 commit 4cf70f8
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 102 deletions.
32 changes: 23 additions & 9 deletions githubplugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,12 @@ def __init__(self, sh):
# '<id2>': {...}
# }
self.repos = {}
self.init_repos = {}

self.repo_path = os.path.join('plugins', 'priv_repos')

# item contains a dict containing the user-defined name for the path of
# each retrieved plugin: {<path to plugin in worktree>: <user-id>}
# each retrieved plugin: {<path1 to plugin in worktree>: <user-id>}
self._repoitem = None

self.gh_apikey = self.get_parameter_value('github_apikey')
Expand Down Expand Up @@ -345,8 +346,7 @@ def read_repos_from_dir(self):
continue

try:
wtname, _ = self._get_last_2_path_parts(target)
owner, _, branch = wtname.split('_')
owner, _, branch = wt.split('_')
except Exception:
self.logger.debug(f'ignoring {target}, not in priv_repos/*_wt_*/plugin form ')
continue
Expand Down Expand Up @@ -398,12 +398,18 @@ def add_repo_to_item(self, repo):

def init_repo(self, name, owner, plugin, branch=None, force=False) -> bool:

if name in self.repos and not force:
self.logger.warning(f'name {name} already taken, not overwriting without force parameter.')
if name in self.repos:
self.logger.warning(f'name {name} already taken, delete old repo first or choose a different name.')
return False

self.repos[name] = {}
repo = self.repos[name]
if name in self.init_repos and not force:
self.logger.warning(f'name {name} already initialized, not overwriting without force parameter.')
return False

if name in self.init_repos and force:
del self.init_repos[name]

repo = {}

# if no plugin is given, make an educated but not very clever guess ;)
repo['plugin'] = plugin
Expand Down Expand Up @@ -439,6 +445,7 @@ def init_repo(self, name, owner, plugin, branch=None, force=False) -> bool:
repo['rel_link_path'] = os.path.join(repo['wt_path'], plugin)

repo['force'] = force
repo['plugin'] = plugin

if os.path.exists(repo['link']) and os.path.islink(repo['link']) and not force:
self.logger.error(f'file {repo["link"]} exists and force is not requested, aborting.')
Expand All @@ -450,15 +457,20 @@ def init_repo(self, name, owner, plugin, branch=None, force=False) -> bool:
self.logger.debug('creating plugins/priv_repos dir')
os.mkdir(os.path.join('plugins', 'priv_repos'))

self.init_repos[name] = repo
return True

def create_repo(self, name) -> bool:

if name not in self.repos:
if name in self.repos:
self.logger.error(f'repo {name} already exists, not overwriting.')
return False

if name not in self.init_repos:
self.logger.warning(f'repo {name} not in own data, unable to process')
return False

repo = self.repos[name]
repo = self.init_repos[name]

self.logger.debug(f'check for repo at {repo["full_repo_path"]}...')

Expand Down Expand Up @@ -541,6 +553,8 @@ def create_repo(self, name) -> bool:
except FileExistsError:
pass

self.repos[name] = self.init_repos[name]
del self.init_repos[name]
self.add_repo_to_item(name)

return True
Expand Down
15 changes: 8 additions & 7 deletions githubplugin/webif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, webif_dir, plugin):
self.tplenv = self.init_template_environment()

@cherrypy.expose
def index(self, reload=None, action=None, prnum=None, owner=None, branch=None, plugin=None):
def index(self):
"""
Build index.html for cherrypy
Expand All @@ -66,9 +66,6 @@ def index(self, reload=None, action=None, prnum=None, owner=None, branch=None, p
"""
# try to get the webif pagelength from the module.yaml configuration
pagelength = self.plugin.get_parameter_value('webif_pagelength')
if action is not None:
if action == "delete_log" and reload is not None:
pass

tmpl = self.tplenv.get_template('index.html')

Expand All @@ -93,10 +90,11 @@ def index(self, reload=None, action=None, prnum=None, owner=None, branch=None, p
return tmpl.render(p=self.plugin,
webif_pagelength=pagelength,
repos=self.plugin.repos,
init_repos=self.plugin.init_repos,
forklist=sorted(self.plugin.gh.forks.keys()),
forks=self.plugin.gh.forks,
pulls=pulls,
tabcount=1, action=action, language=self.plugin.get_sh().get_defaultlanguage())
language=self.plugin.get_sh().get_defaultlanguage())

@cherrypy.expose
@cherrypy.tools.json_out()
Expand Down Expand Up @@ -129,16 +127,18 @@ def selectPlugin(self):
owner = json.get("owner")
branch = json.get("branch")
plugin = json.get("plugin")
name = json.get("name")
confirm = json.get("confirm")
name = f'{owner}/{branch}'

if (owner is None or owner == '' or
branch is None or branch == '' or
plugin is None or plugin == ''):
msg = f'Fehlerhafte Daten für Repo {owner}/plugins, Branch {branch} oder Plugin {plugin} übergeben.'
self.logger.error(msg)
return {"operation": "request", "result": "error", "data": msg}

if confirm:
res = self.plugin.create_repo()
res = self.plugin.create_repo(name)
msg = f'Fehler beim Erstellen des Repos "{owner}/plugins", Branch {branch}, Plugin {plugin}'
else:
res = self.plugin.init_repo(name, owner, plugin, branch)
Expand All @@ -147,6 +147,7 @@ def selectPlugin(self):
if res:
return {"operation": "request", "result": "success"}
else:
self.logger.error(msg)
return {"operation": "request", "result": "error", "data": msg}


Expand Down
50 changes: 50 additions & 0 deletions githubplugin/webif/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* The Modal (background) */
.or-modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 999; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

.in-modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 900; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
.or-modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}

/* The Close Button */
.or-close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}

.or-close:hover,
.or-close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
Loading

0 comments on commit 4cf70f8

Please sign in to comment.