Skip to content

Commit

Permalink
Merge 299eb18 into 273d6e5
Browse files Browse the repository at this point in the history
  • Loading branch information
jaumef committed Jun 6, 2017
2 parents 273d6e5 + 299eb18 commit 224c518
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 255 deletions.
104 changes: 0 additions & 104 deletions hookshub/hooks/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,110 +367,6 @@ def clone_on_dir(dir, repository, url, branch=None):
err = ':clone_repository_fail::{}'.format(err)
return output, new_clone.returncode, err

@staticmethod
def pip_requirements(dir):
"""
Installs all the requirements from the requirements.txt in the specified
directory. If no virtualenv is set previously for the Popen, they will
be installed in the user's python directory
:param dir: Directory where the requirements.txt is found. Used to call
Popen with the pip install.
:type: String
:return: Output with the log. Does not include any of the pip install
output or error prints.
:rtype: String
"""
output = 'Instal.lant dependencies...'
command = 'pip install -r {}'.format(join(dir, 'requirements.txt'))
log_file = join(dir, "pip.log")
command += " > {0} 2> {0}".format(log_file)
dependencies = os.system(command)
with open(log_file, 'r') as stout:
out = stout.read()
os.system('rm {}'.format(log_file))
if dependencies != 0:
output += ' Couldn\'t install all dependencies!\n{}'.format(
out
)
else:
output += " OK"
return output

@staticmethod
def export_pythonpath(docs_path):
"""
:param docs_path: Path to the docs clone. Must have the sitecustomize
directory, as that's what the $PYTHONPATH will point to
:type: String
:return: An output log saying if everything was ok
"""
sc_path = join(docs_path, 'sitecustomize')
command = 'export PYTHONPATH={}'.format(sc_path)
try:
export = Popen(
command.split(), cwd=docs_path, stdout=PIPE, stderr=PIPE
)
if export.returncode == 0:
output = 'Success to export sitecustomize path'
else:
output = 'Failed to export sitecustomize path'
except Exception as err:
output = 'Failed to export sitecustomize path'
return output

@staticmethod
def docs_build(dir, target=None, file=None, clean=True):
"""
:param dir: Directory used to call the build. This MUST exist.
:type: String
:param file: Configuration file used to build with. If None is set,
the '-f' option is not used, using the default 'mkdocs.yml' config
:type: String
:param target: Directory to build to. If not set or None, the target
build is the default one, that is the same as 'dir'
:type: String
:param clean: Defines if the '--clean' tag is used or not. If true,
this cleans the directory before the build.
:type: Bool
:return: The command to all with the specified params, thus not all
environments support processes (or are not desired)
"""
build_path = dir
output = 'Building mkdocs from {} '.format(dir)
command = 'cd {} && mkdocs build'.format(dir)
if target:
build_path = target
output += 'to {}...'.format(target)
command += ' -d {}'.format(target)
if file:
output += ' using file config file "{}"...'.format(file)
command += ' -f {}'.format(file)
if clean:
command += ' --clean'
log_file = join(dir, 'build.log')
command += " > {0} 2> {0}".format(log_file)
new_build = os.system(command)
with open(log_file, 'r') as stout:
out = stout.read()
os.system('rm {}'.format(log_file))
if new_build != 0:
output += 'FAILED TO BUILD: {}'.format(out)
return output, False
output += " OK"
return output, build_path

@staticmethod
def create_virtualenv(name='foo', dir='/tmp/venv'):
if not isdir(dir):
os.system('mkdir -p {}'.format(dir))
dest = join(dir, name)
log = '{}.log'.format(name)
logs = join(dir, log)
os.system('virtualenv {0} > {1} 2> {1}'.format(dest, logs))
activate = join(dest, 'bin', 'activate_this.py')
execfile(activate, dict(__file__=activate))
return dest

@staticmethod
def get_pr(token, repository, branch):
"""
Expand Down
11 changes: 6 additions & 5 deletions hookshub/hooks/github_hooks/pull_request-powerp-docs_newPR.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from json import loads, dumps
from os.path import join
from hookshub.hooks.github import GitHubUtil as Util
from hookshub import utils

import sys
import tempfile
Expand Down Expand Up @@ -40,7 +41,7 @@ def arguments():
http_url = "https://api.github.com"

action = payload['action']
if action != Util.actions['ACT_REOPENED'] and\
if action != Util.actions['ACT_REOPENED'] and \
action != Util.actions['ACT_OPENED']:
output = 'PR is "{}", not "{}" or "{}".\nAborting ...'.format(
action, Util.actions['ACT_OPENED'], Util.actions['ACT_REOPENED']
Expand Down Expand Up @@ -112,16 +113,16 @@ def arguments():
clone_dir = join(temp.dir, repo_name)

# Crear Virtualenv en el directori temporal
Util.create_virtualenv(temp.dir, branch_name)
utils.create_virtualenv(temp.dir, branch_name)

# Instalem dependencies

output += '{} |'.format(Util.pip_requirements(clone_dir) or 'OK')
output += '{} |'.format(utils.pip_requirements(clone_dir) or 'OK')

# Fem build al directori on tenim la pagina des del directori del clone
# Build en català
out, target_build_path = (
Util.docs_build(clone_dir, ca_docs_path, None, True)
utils.mkdocs_build(clone_dir, ca_docs_path, None, True)
)

# If build fails we can't continue
Expand All @@ -133,7 +134,7 @@ def arguments():

# Build en castellà
out, target_build_path = (
Util.docs_build(clone_dir, es_docs_path, 'mkdocs_es.yml', True)
utils.mkdocs_build(clone_dir, es_docs_path, 'mkdocs_es.yml', True)
)

# If build fails we can't continue
Expand Down
9 changes: 5 additions & 4 deletions hookshub/hooks/github_hooks/push-powerp-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from json import loads, dumps
from os.path import join
from hookshub.hooks.github import GitHubUtil as Util
from hookshub import utils

import sys
import tempfile
Expand Down Expand Up @@ -98,18 +99,18 @@ def arguments():
clone_dir = join(temp.dir, repo_name)

# Crear Virtualenv en el directori temporal
Util.create_virtualenv(temp.dir, branch_name)
utils.create_virtualenv(temp.dir, branch_name)

# Instalem dependencies

output += Util.pip_requirements(clone_dir)
output += utils.pip_requirements(clone_dir)

# Fem build al directori on tenim la pàgina des del directori del clone

# Build en català

out, target_build_path = (
Util.docs_build(clone_dir, ca_docs_path, None, True)
utils.docs_build(clone_dir, ca_docs_path, None, True)
)
# If build fails we can't continue
if not target_build_path:
Expand All @@ -121,7 +122,7 @@ def arguments():
# Build en castellà

out, target_build_path = (
Util.docs_build(clone_dir, es_docs_path, 'mkdocs_es.yml', True)
utils.docs_build(clone_dir, es_docs_path, 'mkdocs_es.yml', True)
)
# If build fails we can't continue
if not target_build_path:
Expand Down
66 changes: 2 additions & 64 deletions hookshub/hooks/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def get_exe_action(self, action, conf):
args = [args[0], dumps(json)]
return args


class GitLabUtil:

@staticmethod
def clone_on_dir(dir, branch, repository, url):
"""
Expand Down Expand Up @@ -205,70 +207,6 @@ def clone_on_dir(dir, branch, repository, url):
err = ':clone_repository_fail::{}'.format(err)
return output, new_clone.returncode, err

@staticmethod
def pip_requirements(dir):
"""
Installs all the requirements from the requirements.txt in the specified
directory. If no virtualenv is set previously for the Popen, they will
be installed in the user's python directory
:param dir: Directory where the requirements.txt is found. Used to call
Popen with the pip install.
:type: String
:return: Output with the log. Does not include any of the pip install
output or error prints.
:rtype: String
"""
output = 'Instal.lant dependencies...'
command = 'pip install -r requirements.txt'
dependencies = Popen(
command.split(), cwd=dir, stdout=PIPE, stderr=PIPE
)
out, err = dependencies.communicate()
if dependencies.returncode != 0:
output += ' Couldn\'t install all dependencies '
return output

@staticmethod
def lektor_build(dir, target=None, project=None):
"""
:param dir: Directory used to call the build. This MUST exist.
:type: String
:param target: Directory to build to. If not set or None, the target
build is the default one, that is the same as 'dir'
:type: String
:param project: Project to find in the directory, used by lektor command
May be None, and is not used if in the right directory.
:type: String
:return: An output log with some annotations and the output and error
log from the lektor build call. And a String containing the path
where the docs have been built
:type: Tuple<String, String>
"""
build_path = dir
output = 'Building lector from {} '.format(dir)
command = 'lektor '
if project:
output += 'for the project {} '.format(project)
command += '--project {}'.format(project)
command += ' build'
if target:
build_path = target
output += 'to {}...'.format(target)
command += ' -O {}'.format(target)
try:
new_build = Popen(
command.split(), cwd=dir, stdout=PIPE, stderr=PIPE
)
out, err = new_build.communicate()
if new_build.returncode != 0:
output += 'FAILED TO BUILD: {0}::{1}'.format(out, err)
return output, False
except Exception as err:
output += 'Build Failed with exception from Popen... {}'.format(err)
return output, False

return output, build_path

@staticmethod
def post_comment_mr(http_url, token, project, merge_num, message):
"""
Expand Down
8 changes: 4 additions & 4 deletions hookshub/hooks/gitlab_hooks/merge_request_lektor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tempfile import mkdtemp
from shutil import rmtree
from hookshub.hooks.gitlab import GitLabUtil as Util
from hookshub import utils
import sys


Expand Down Expand Up @@ -98,15 +99,14 @@ def arguments():

clone_dir = join(tmp_dir, repo_name)

# Pendent de solucionar: No es pot entrar al virtualenv si amb el binari
# especificat a dalt... A més l'interpret no pot canviar amb subprocess
utils.create_virtualenv(name='lektor', dir=tmp_dir)

output += 'Instal.lant dependencies...'
output += '{} DONE |'.format(Util.pip_requirements(clone_dir))
output += '{} DONE |'.format(utils.pip_requirements(clone_dir))

# Fem build al directori on tenim la pagina des del directori del clone
path = master_path if merged else branch_path
out, ret_path = Util.lektor_build(
out, ret_path = utils.lektor_build(
clone_dir, path, 'gisce.net-lektor'
)
output += out
Expand Down
Loading

0 comments on commit 224c518

Please sign in to comment.