Commit a3c09a4b authored by Marco Mariani's avatar Marco Mariani

runner: grammar nazi

parent ab224625
...@@ -15,7 +15,7 @@ from slapos.runner.utils import realpath, tail, isText ...@@ -15,7 +15,7 @@ from slapos.runner.utils import realpath, tail, isText
class FileBrowser(object): class FileBrowser(object):
"""This class contain all base functions for file browser""" """This class contains all base functions for file browser"""
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
...@@ -115,7 +115,7 @@ class FileBrowser(object): ...@@ -115,7 +115,7 @@ class FileBrowser(object):
details = realfile.split('/') details = realfile.split('/')
dest = os.path.join(realdir, details[-1]) dest = os.path.join(realdir, details[-1])
if os.path.exists(dest): if os.path.exists(dest):
raise NameError('NOT ALLOWED OPERATION : File or directory already exist') raise NameError('NOT ALLOWED OPERATION : File or directory already exists')
if os.path.isdir(realfile): if os.path.isdir(realfile):
shutil.copytree(realfile, dest) shutil.copytree(realfile, dest)
if del_source: if del_source:
...@@ -138,7 +138,7 @@ class FileBrowser(object): ...@@ -138,7 +138,7 @@ class FileBrowser(object):
if not os.path.exists(tofile): if not os.path.exists(tofile):
os.rename(realfile, tofile) os.rename(realfile, tofile)
return "{result: '1'}" return "{result: '1'}"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist') raise NameError('NOT ALLOWED OPERATION : File or directory already exists')
def copyAsFile(self, dir, filename, newfilename): def copyAsFile(self, dir, filename, newfilename):
"""Copy file or directory to dir/filename""" """Copy file or directory to dir/filename"""
...@@ -146,14 +146,14 @@ class FileBrowser(object): ...@@ -146,14 +146,14 @@ class FileBrowser(object):
fromfile = os.path.join(realdir, filename) fromfile = os.path.join(realdir, filename)
tofile = os.path.join(realdir, newfilename) tofile = os.path.join(realdir, newfilename)
if not os.path.exists(fromfile): if not os.path.exists(fromfile):
raise NameError('NOT ALLOWED OPERATION : File or directory not exist') raise NameError('NOT ALLOWED OPERATION : File or directory does not exist')
if not os.path.exists(tofile): if not os.path.exists(tofile):
shutil.copy(fromfile, tofile) shutil.copy(fromfile, tofile)
return "{result: '1'}" return "{result: '1'}"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist') raise NameError('NOT ALLOWED OPERATION : File or directory already exists')
def uploadFile(self, dir, files): def uploadFile(self, dir, files):
"""Upload a list of file in directory dir""" """Upload a list of files in directory dir"""
realdir = self._realdir(dir) realdir = self._realdir(dir)
for file in files: for file in files:
if files[file]: if files[file]:
...@@ -177,7 +177,7 @@ class FileBrowser(object): ...@@ -177,7 +177,7 @@ class FileBrowser(object):
tozip = os.path.join(realdir, newfilename) tozip = os.path.join(realdir, newfilename)
fromzip = os.path.join(realdir, filename) fromzip = os.path.join(realdir, filename)
if not os.path.exists(fromzip): if not os.path.exists(fromzip):
raise NameError('NOT ALLOWED OPERATION : File or directory not exist') raise NameError('NOT ALLOWED OPERATION : File or directory does not exist')
if not os.path.exists(tozip): if not os.path.exists(tozip):
zip = zipfile.ZipFile(tozip, 'w', zipfile.ZIP_DEFLATED) zip = zipfile.ZipFile(tozip, 'w', zipfile.ZIP_DEFLATED)
if os.path.isdir(fromzip): if os.path.isdir(fromzip):
...@@ -190,7 +190,7 @@ class FileBrowser(object): ...@@ -190,7 +190,7 @@ class FileBrowser(object):
zip.write(fromzip) zip.write(fromzip)
zip.close() zip.close()
return "{result: '1'}" return "{result: '1'}"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist') raise NameError('NOT ALLOWED OPERATION : File or directory already exists')
def unzipFile(self, dir, filename, newfilename): def unzipFile(self, dir, filename, newfilename):
"""Extract a zipped archive""" """Extract a zipped archive"""
...@@ -198,7 +198,7 @@ class FileBrowser(object): ...@@ -198,7 +198,7 @@ class FileBrowser(object):
target = os.path.join(realdir, newfilename) target = os.path.join(realdir, newfilename)
archive = os.path.join(realdir, filename) archive = os.path.join(realdir, filename)
if not os.path.exists(archive): if not os.path.exists(archive):
raise NameError('NOT ALLOWED OPERATION : File or directory not exist') raise NameError('NOT ALLOWED OPERATION : File or directory does not exist')
if not os.path.exists(target): if not os.path.exists(target):
zip = zipfile.ZipFile(archive) zip = zipfile.ZipFile(archive)
#member = zip.namelist() #member = zip.namelist()
...@@ -208,7 +208,7 @@ class FileBrowser(object): ...@@ -208,7 +208,7 @@ class FileBrowser(object):
#else: #else:
# zip.extract(member[0], newfilename) # zip.extract(member[0], newfilename)
return "{result: '1'}" return "{result: '1'}"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist') raise NameError('NOT ALLOWED OPERATION : File or directory already exists')
def readFile(self, dir, filename, truncate=False): def readFile(self, dir, filename, truncate=False):
"""Read file dir/filename and return content""" """Read file dir/filename and return content"""
......
...@@ -12,19 +12,19 @@ from flask import jsonify ...@@ -12,19 +12,19 @@ from flask import jsonify
def cloneRepo(data): def cloneRepo(data):
"""Clonne a repository """Clone a repository
Args: Args:
data: a dictionary of parameters to use: data: a dictionary of parameters to use:
data['path'] is the path of the new project data['path'] is the path of the new project
data['repo'] is the url of the repository to be cloned data['repo'] is the url of the repository to be cloned
data['email'] is the user email data['email'] is the user's email
data['user'] is the name of the user data['user'] is the name of the user
Returns: Returns:
a jsonify data""" a jsonify data"""
workDir = data['path'] workDir = data['path']
if not workDir: if not workDir:
return jsonify(code=0, return jsonify(code=0,
result="Can not create project folder: Permission Denied") result="Cannot create project folder: Permission Denied")
code = 0 code = 0
json = "" json = ""
try: try:
...@@ -46,7 +46,7 @@ def cloneRepo(data): ...@@ -46,7 +46,7 @@ def cloneRepo(data):
def gitStatus(project): def gitStatus(project):
"""Run git status and return status of specified project folder """Run git status and return status of specified project folder
Args: Args:
project: path of the projet ti get status project: path of the projet to get status
Returns: Returns:
a parsed string that contains the result of git status""" a parsed string that contains the result of git status"""
code = 0 code = 0
...@@ -146,7 +146,7 @@ def gitPush(project, msg): ...@@ -146,7 +146,7 @@ def gitPush(project, msg):
git.push('origin', current_branch) git.push('origin', current_branch)
code = 1 code = 1
else: else:
json = "Nothing to be commited" json = "Nothing to commit"
code = 1 code = 1
except Exception as e: except Exception as e:
if undo_commit: if undo_commit:
......
...@@ -9,7 +9,7 @@ SLAPRUNNER_PROCESS_LIST = [] ...@@ -9,7 +9,7 @@ SLAPRUNNER_PROCESS_LIST = []
class Popen(subprocess.Popen): class Popen(subprocess.Popen):
""" """
Extension of Popen to launch and kill process in a clean way Extension of Popen to launch and kill processes in a clean way
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
""" """
...@@ -28,7 +28,7 @@ class Popen(subprocess.Popen): ...@@ -28,7 +28,7 @@ class Popen(subprocess.Popen):
def kill(self, sig=signal.SIGTERM, recursive=False): def kill(self, sig=signal.SIGTERM, recursive=False):
""" """
Kill process and all its descendant if recursive Kill process and all its descendants if recursive
""" """
if self.poll() is None: if self.poll() is None:
if recursive: if recursive:
...@@ -83,7 +83,7 @@ def isRunning(name): ...@@ -83,7 +83,7 @@ def isRunning(name):
def killRunningProcess(name, recursive=False): def killRunningProcess(name, recursive=False):
""" """
Kill all process with name Kill all processes with a given name
""" """
for process in SLAPRUNNER_PROCESS_LIST: for process in SLAPRUNNER_PROCESS_LIST:
if process.name == name: if process.name == name:
...@@ -92,7 +92,7 @@ def killRunningProcess(name, recursive=False): ...@@ -92,7 +92,7 @@ def killRunningProcess(name, recursive=False):
def handler(sig, frame): def handler(sig, frame):
""" """
Signal handler to kill all process Signal handler to kill all processes
""" """
pid = os.getpid() pid = os.getpid()
os.kill(-pid, sig) os.kill(-pid, sig)
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
import argparse import argparse
import ConfigParser import ConfigParser
import datetime import datetime
import hashlib
import json import json
import os import os
import shutil import shutil
import time import time
import unittest import unittest
import hashlib
from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning, from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning,
isSoftwareRunning, startProxy) isSoftwareRunning, startProxy)
...@@ -174,7 +174,7 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -174,7 +174,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self.assertEqual(proxy, status) self.assertEqual(proxy, status)
def setupProjectFolder(self, withSoftware=False): def setupProjectFolder(self, withSoftware=False):
"""Helper for create a project folder as for slapos.git""" """Helper to create a project folder as for slapos.git"""
base = os.path.join(self.app.config['workspace'], 'slapos') base = os.path.join(self.app.config['workspace'], 'slapos')
software = os.path.join(base, 'software') software = os.path.join(base, 'software')
os.mkdir(base) os.mkdir(base)
...@@ -193,7 +193,7 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -193,7 +193,7 @@ class SlaprunnerTestCase(unittest.TestCase):
'w').write(sr) 'w').write(sr)
def setupSoftwareFolder(self): def setupSoftwareFolder(self):
"""Helper for setup compiled software release dir""" """Helper to setup compiled software release dir"""
self.setupProjectFolder(withSoftware=True) self.setupProjectFolder(withSoftware=True)
md5 = hashlib.md5(os.path.join(self.app.config['workspace'], md5 = hashlib.md5(os.path.join(self.app.config['workspace'],
"slapos/software/slaprunner-test", "slapos/software/slaprunner-test",
...@@ -218,7 +218,7 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -218,7 +218,7 @@ class SlaprunnerTestCase(unittest.TestCase):
#Begin test case here #Begin test case here
def test_wrong_login(self): def test_wrong_login(self):
"""Test Login user before create session. This should return error value""" """Test Login user before create session. This should return an error value"""
response = self.login(self.users[0], self.users[1]) response = self.login(self.users[0], self.users[1])
#redirect to config account page #redirect to config account page
assert "<h2 class='title'>Your personal information</h2><br/>" in response.data assert "<h2 class='title'>Your personal information</h2><br/>" in response.data
...@@ -249,7 +249,7 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -249,7 +249,7 @@ class SlaprunnerTestCase(unittest.TestCase):
assert "<h2>Login to Slapos Web Runner</h2>" in result.data assert "<h2>Login to Slapos Web Runner</h2>" in result.data
def test_updateAccount(self): def test_updateAccount(self):
"""test Update accound, this need user to loging in""" """test Update accound, this needs the user to log in"""
self.setAccount() self.setAccount()
response = loadJson(self.updateAccount(self.updateUser, self.rcode)) response = loadJson(self.updateAccount(self.updateUser, self.rcode))
self.assertEqual(response['code'], 1) self.assertEqual(response['code'], 1)
......
...@@ -3,12 +3,10 @@ ...@@ -3,12 +3,10 @@
# pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142 # pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142
import md5
import logging import logging
import md5
import multiprocessing import multiprocessing
import re import re
from slapos.runner.process import Popen, isRunning, killRunningProcess
from slapos.htpasswd import HtpasswdFile
import shutil import shutil
import os import os
import time import time
...@@ -18,6 +16,8 @@ from xml.dom import minidom ...@@ -18,6 +16,8 @@ from xml.dom import minidom
import xml_marshaller import xml_marshaller
from flask import jsonify from flask import jsonify
from slapos.runner.process import Popen, isRunning, killRunningProcess
from slapos.htpasswd import HtpasswdFile
import slapos.slap import slapos.slap
# Setup default flask (werkzeug) parser # Setup default flask (werkzeug) parser
......
...@@ -490,8 +490,7 @@ def slapgridResult(): ...@@ -490,8 +490,7 @@ def slapgridResult():
'position': 0, 'position': 0,
'truncated': False 'truncated': False
} }
if request.form['log'] == "software" or \ if request.form['log'] in ['software', 'instance']:
request.form['log'] == "instance":
log_file = request.form['log'] + "_log" log_file = request.form['log'] + "_log"
if os.path.exists(app.config[log_file]): if os.path.exists(app.config[log_file]):
log_result = readFileFrom(open(app.config[log_file]), log_result = readFileFrom(open(app.config[log_file]),
......
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