├── pytest.ini ├── mayatdd ├── __init__.py ├── unittest_wrapper_test.py ├── userSetup.py ├── server_test.py ├── server.py ├── launchMaya.py └── mayatest.py ├── tox.ini ├── .gitignore ├── Pipfile ├── setup.py ├── readme.md ├── Pipfile.lock └── LICENSE /pytest.ini: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mayatdd/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27,py37 3 | [testenv] 4 | deps = pytest 5 | commands = pytest -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | .project 3 | .pydevproject 4 | dist 5 | *.egg-info 6 | .idea 7 | /.tox/ 8 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [dev-packages] 7 | 8 | [packages] 9 | pytest = "*" 10 | tox = "*" 11 | tox-pyenv = "*" 12 | -------------------------------------------------------------------------------- /mayatdd/unittest_wrapper_test.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mayatdd.mayatest import mayaTest 4 | 5 | 6 | @mayaTest('mayatdd') 7 | class RunMeInMaya(unittest.TestCase): 8 | def testSomething(self): 9 | pass -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup( 4 | name="mayatdd", 5 | version="0.0.2", 6 | packages=["mayatdd"], 7 | include_package_data=True, 8 | install_requires=[], 9 | dependency_links=[], 10 | ) 11 | -------------------------------------------------------------------------------- /mayatdd/userSetup.py: -------------------------------------------------------------------------------- 1 | ''' 2 | this module will be copied into launched maya's /scripts folder 3 | ''' 4 | 5 | import sys 6 | import os 7 | 8 | def info(message): 9 | print message 10 | sys.stdout.flush() 11 | 12 | info("Configuring Maya for test execution..") 13 | 14 | 15 | testPythonPath = os.environ.get('maya_test_pythonpath') 16 | if testPythonPath is not None: 17 | for i in testPythonPath.split(";"): 18 | info("adding python path: "+i) 19 | sys.path.append(i) 20 | 21 | from mayatdd import mayatest, server 22 | 23 | info("Starting TDD server...") 24 | server.Server(9025).run(mayatest.serverHandler) 25 | info("Maya is ready for some tests!") 26 | -------------------------------------------------------------------------------- /mayatdd/server_test.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mayatdd import server 4 | 5 | 6 | class ServerTest(unittest.TestCase): 7 | def setUp(self): 8 | self.server = None 9 | self.port = 6778 10 | self.server = server.Server(self.port) 11 | 12 | def testConnect(self): 13 | ''' 14 | validate that server-client connection is happening and that handler is installed correctly 15 | ''' 16 | 17 | def fakeHandler(request): 18 | if "validRequest" in request: 19 | return {'response': request['validRequest']} 20 | else: 21 | return 'not the right thing received' 22 | 23 | self.server.run(fakeHandler) 24 | 25 | for i in range(100): 26 | client = server.Client("127.0.0.1", self.port) 27 | result = client.send({'validRequest': i}) 28 | self.assertEqual(result, {'response': i}) 29 | 30 | def tearDown(self): 31 | if self.server is not None: 32 | self.server.stop() 33 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Maya TDD setup 2 | 3 | I'm trying to publish some code in relation to my [TDD in Maya article](http://viktorasm.github.io/tdd/maya/2015/01/01/automated-testing-maya-plugin-development.html). Before it's been a seamless part of the rest of [ngSkinTools](http://www.ngskintools.com) project, but as I'm finding that I need to repeat this setup in other Maya-related projects, this is my attempt to make it a reusable library. 4 | 5 | ## Installation (venv) 6 | 7 | * Create your virtual environment 8 | 9 | ```bash 10 | virtualenv venv 11 | source venv/bin/activate 12 | ``` 13 | 14 | * Install this package: 15 | 16 | ```bash 17 | pip install git+https://github.com/viktorasm/maya-tdd-toolkit.git 18 | ``` 19 | 20 | ## Installation (pipenv) 21 | 22 | Specify in your `Pipfile`: 23 | 24 | ```toml 25 | [dev-packages] 26 | pytest = "*" 27 | mayatdd = {git = "https://github.com/viktorasm/maya-tdd-toolkit.git", ref = "master"} 28 | ``` 29 | 30 | ## Sample project 31 | 32 | Checkout [maya-tdd-toolkit-sampleproject](https://github.com/viktorasm/maya-tdd-toolkit-sampleproject) for an example. 33 | -------------------------------------------------------------------------------- /mayatdd/server.py: -------------------------------------------------------------------------------- 1 | ''' 2 | simple RPC over HTTP 3 | ''' 4 | 5 | import threading 6 | import json 7 | import socket 8 | 9 | try: 10 | from BaseHTTPServer import BaseHTTPRequestHandler 11 | from SocketServer import TCPServer 12 | except: 13 | from http.server import BaseHTTPRequestHandler 14 | from socketserver import TCPServer 15 | 16 | 17 | class Client: 18 | def __init__(self, host, port): 19 | self.timeout = 300 20 | self.endpoint = "http://{0}:{1}".format(host, port) 21 | 22 | def send(self, jsonDictionary): 23 | ''' 24 | sends JSON over the HTTP POST and returns parsed JSON as result 25 | 26 | no particular error checking is done as we trust our server in a way. 27 | ''' 28 | data = json.dumps(jsonDictionary).encode("utf-8") 29 | 30 | try: 31 | from urllib2 import urlopen 32 | except: 33 | from urllib.request import urlopen 34 | 35 | response = urlopen(self.endpoint, data=data, timeout=self.timeout) 36 | return json.loads(response.read()) 37 | 38 | 39 | class Server: 40 | 41 | def __init__(self, port): 42 | self.port = port 43 | self.instance = None 44 | self.instance_thread = None 45 | 46 | 47 | def run(self, requestHandlerMethod): 48 | class RequestHandler(BaseHTTPRequestHandler): 49 | 50 | def do_GET(self): 51 | self.wfile.write("maya tdd server\n") 52 | 53 | def log_message(self, format, *args): 54 | return 55 | 56 | 57 | def do_POST(self): 58 | request = self.rfile.read(int(self.headers['Content-Length'])) 59 | request = json.loads(request) 60 | result = requestHandlerMethod(request) 61 | 62 | self.send_response(200) 63 | self.end_headers() 64 | self.wfile.write(json.dumps(result).encode("utf-8")) 65 | 66 | self.instance = TCPServer(("", self.port), RequestHandler, bind_and_activate=False) 67 | self.instance.allow_reuse_address = True 68 | self.instance.server_bind() 69 | self.instance.server_activate() 70 | self.instance_thread = threading.Thread(target=self.instance.serve_forever) 71 | self.instance_thread.start() 72 | 73 | def stop(self): 74 | if self.instance is not None: 75 | self.instance.shutdown() 76 | self.instance_thread.join() 77 | self.instance.server_close() 78 | -------------------------------------------------------------------------------- /mayatdd/launchMaya.py: -------------------------------------------------------------------------------- 1 | ''' 2 | launch maya with settings that will enable launching tests with provided scripts; 3 | feedbacks all stdout output back to IDE 4 | ''' 5 | import subprocess 6 | import os 7 | import shutil 8 | 9 | import platform 10 | 11 | class Launcher: 12 | def __init__(self): 13 | self.isWindows = 'windows' in platform.system().lower() 14 | self.isLinux = 'linux' in platform.system().lower() 15 | 16 | self.mayaExecutable=os.path.join(os.environ['MAYA_HOME'],'bin','maya') 17 | if self.isWindows: 18 | self.mayaExecutable += ".exe" 19 | 20 | self.mayaPath = None 21 | self.projectDir = os.path.abspath(os.path.dirname(__file__)+"/..") 22 | self.mayaEnvTemplateDir = self.projectDir+'/testMayaLaunchEnvironment_snapshot' 23 | self.projectWorkspace = os.path.abspath(os.path.dirname(__file__)+"/../../") 24 | 25 | # add dcc automation 26 | self.pythonPath = [] 27 | # add self to path 28 | self.pythonPath.append(self.projectDir) 29 | # add site-packages 30 | from distutils.sysconfig import get_python_lib; 31 | self.pythonPath.append(get_python_lib()) 32 | 33 | self.parseCommandLine() 34 | 35 | def configure(self): 36 | self.mayaEnvDir = os.path.abspath(self.mayaEnvTemplateDir+"_workingcopy") 37 | 38 | if self.isWindows: 39 | self.mayaPath = os.path.dirname(self.mayaExecutable) 40 | 41 | self.mayaUserDir = self.mayaEnvDir+"/2015-x64" 42 | self.mayaModulesDir = os.path.join(self.mayaUserDir,"modules") 43 | self.mayaShelvesDir = self.mayaUserDir+"/prefs/shelves" 44 | 45 | def parseCommandLine(self): 46 | from optparse import OptionParser 47 | parser = OptionParser() 48 | parser.add_option("-m", "--mode", dest="mode", 49 | help="maya mode (test, production)") 50 | 51 | self.options,_ = parser.parse_args() 52 | 53 | if self.options.mode is None: 54 | self.options.mode = 'test' 55 | 56 | def createEnvDir(self): 57 | if os.path.exists(self.mayaEnvDir): 58 | shutil.rmtree(self.mayaEnvDir,ignore_errors=False) 59 | shutil.copytree(self.mayaEnvTemplateDir, self.mayaEnvDir) 60 | 61 | scriptsDir = self.mayaEnvDir+'/scripts' 62 | if not os.path.exists(scriptsDir): 63 | os.makedirs(scriptsDir) 64 | 65 | shutil.copy2(os.path.dirname(__file__)+'/userSetup.py', scriptsDir) 66 | 67 | def launch(self): 68 | self.configure() 69 | 70 | env = os.environ.copy() 71 | env['MAYA_APP_DIR'] = self.mayaEnvDir 72 | if self.mayaPath is not None: 73 | env['MAYA_LOCATION'] = self.mayaPath 74 | env['PATH'] = self.mayaPath 75 | 76 | env.pop('PYTHONPATH',None) 77 | env.pop('PYTHONHOME',None) 78 | env.pop('PYTHONIOENCODING',None) 79 | env.pop('PYTHONUNBUFFERED',None) 80 | 81 | 82 | 83 | self.createEnvDir() 84 | 85 | env['maya_test_pythonpath'] = ';'.join(self.pythonPath) 86 | 87 | options ={'env':env} 88 | if self.mayaPath is not None: 89 | options['cwd'] = self.mayaPath 90 | 91 | print "starting Maya with options:" 92 | print "python path:",self.pythonPath 93 | print "environment template:",self.mayaEnvTemplateDir 94 | print "launch mode:",self.options.mode 95 | 96 | commandLine = [self.mayaExecutable,'-nosplash'] 97 | if self.isLinux: 98 | commandLine = ["/bin/csh","-f"]+commandLine 99 | print "command line:"," ".join(commandLine) 100 | 101 | subprocess.Popen(commandLine,**options).communicate() 102 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "11658a22b6aff52224d32a4de5ede4c724652e6519997e826eb45177124263a9" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": {}, 8 | "sources": [ 9 | { 10 | "name": "pypi", 11 | "url": "https://pypi.org/simple", 12 | "verify_ssl": true 13 | } 14 | ] 15 | }, 16 | "default": { 17 | "attrs": { 18 | "hashes": [ 19 | "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c", 20 | "sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72" 21 | ], 22 | "version": "==19.3.0" 23 | }, 24 | "filelock": { 25 | "hashes": [ 26 | "sha256:18d82244ee114f543149c66a6e0c14e9c4f8a1044b5cdaadd0f82159d6a6ff59", 27 | "sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836" 28 | ], 29 | "version": "==3.0.12" 30 | }, 31 | "importlib-metadata": { 32 | "hashes": [ 33 | "sha256:06f5b3a99029c7134207dd882428a66992a9de2bef7c2b699b5641f9886c3302", 34 | "sha256:b97607a1a18a5100839aec1dc26a1ea17ee0d93b20b0f008d80a5a050afb200b" 35 | ], 36 | "markers": "python_version < '3.8'", 37 | "version": "==1.5.0" 38 | }, 39 | "more-itertools": { 40 | "hashes": [ 41 | "sha256:5dd8bcf33e5f9513ffa06d5ad33d78f31e1931ac9a18f33d37e77a180d393a7c", 42 | "sha256:b1ddb932186d8a6ac451e1d95844b382f55e12686d51ca0c68b6f61f2ab7a507" 43 | ], 44 | "version": "==8.2.0" 45 | }, 46 | "packaging": { 47 | "hashes": [ 48 | "sha256:170748228214b70b672c581a3dd610ee51f733018650740e98c7df862a583f73", 49 | "sha256:e665345f9eef0c621aa0bf2f8d78cf6d21904eef16a93f020240b704a57f1334" 50 | ], 51 | "version": "==20.1" 52 | }, 53 | "pluggy": { 54 | "hashes": [ 55 | "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0", 56 | "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d" 57 | ], 58 | "version": "==0.13.1" 59 | }, 60 | "py": { 61 | "hashes": [ 62 | "sha256:5e27081401262157467ad6e7f851b7aa402c5852dbcb3dae06768434de5752aa", 63 | "sha256:c20fdd83a5dbc0af9efd622bee9a5564e278f6380fffcacc43ba6f43db2813b0" 64 | ], 65 | "version": "==1.8.1" 66 | }, 67 | "pyparsing": { 68 | "hashes": [ 69 | "sha256:4c830582a84fb022400b85429791bc551f1f4871c33f23e44f353119e92f969f", 70 | "sha256:c342dccb5250c08d45fd6f8b4a559613ca603b57498511740e65cd11a2e7dcec" 71 | ], 72 | "version": "==2.4.6" 73 | }, 74 | "pytest": { 75 | "hashes": [ 76 | "sha256:0d5fe9189a148acc3c3eb2ac8e1ac0742cb7618c084f3d228baaec0c254b318d", 77 | "sha256:ff615c761e25eb25df19edddc0b970302d2a9091fbce0e7213298d85fb61fef6" 78 | ], 79 | "index": "pypi", 80 | "version": "==5.3.5" 81 | }, 82 | "six": { 83 | "hashes": [ 84 | "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a", 85 | "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c" 86 | ], 87 | "version": "==1.14.0" 88 | }, 89 | "toml": { 90 | "hashes": [ 91 | "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", 92 | "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e", 93 | "sha256:f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3" 94 | ], 95 | "version": "==0.10.0" 96 | }, 97 | "tox": { 98 | "hashes": [ 99 | "sha256:06ba73b149bf838d5cd25dc30c2dd2671ae5b2757cf98e5c41a35fe449f131b3", 100 | "sha256:806d0a9217584558cc93747a945a9d9bff10b141a5287f0c8429a08828a22192" 101 | ], 102 | "index": "pypi", 103 | "version": "==3.14.3" 104 | }, 105 | "tox-pyenv": { 106 | "hashes": [ 107 | "sha256:916c2213577aec0b3b5452c5bfb32fd077f3a3196f50a81ad57d7ef3fc2599e4", 108 | "sha256:e470c18af115fe52eeff95e7e3cdd0793613eca19709966fc2724b79d55246cb" 109 | ], 110 | "index": "pypi", 111 | "version": "==1.1.0" 112 | }, 113 | "virtualenv": { 114 | "hashes": [ 115 | "sha256:0d62c70883c0342d59c11d0ddac0d954d0431321a41ab20851facf2b222598f3", 116 | "sha256:55059a7a676e4e19498f1aad09b8313a38fcc0cdbe4fdddc0e9b06946d21b4bb" 117 | ], 118 | "version": "==16.7.9" 119 | }, 120 | "wcwidth": { 121 | "hashes": [ 122 | "sha256:8fd29383f539be45b20bd4df0dc29c20ba48654a41e661925e612311e9f3c603", 123 | "sha256:f28b3e8a6483e5d49e7f8949ac1a78314e740333ae305b4ba5defd3e74fb37a8" 124 | ], 125 | "version": "==0.1.8" 126 | }, 127 | "zipp": { 128 | "hashes": [ 129 | "sha256:ccc94ed0909b58ffe34430ea5451f07bc0c76467d7081619a454bf5c98b89e28", 130 | "sha256:feae2f18633c32fc71f2de629bfb3bd3c9325cd4419642b1f1da42ee488d9b98" 131 | ], 132 | "version": "==2.1.0" 133 | } 134 | }, 135 | "develop": {} 136 | } 137 | -------------------------------------------------------------------------------- /mayatdd/mayatest.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | from functools import wraps 4 | import inspect 5 | import sys 6 | import importlib 7 | import random 8 | import pickle 9 | import base64 10 | 11 | import functools 12 | from imp import reload 13 | 14 | try: 15 | from maya import cmds 16 | # just assume that if cmds is available, we're inside maya 17 | insideMaya = cmds.about(version=True) is not None 18 | except: 19 | insideMaya = False 20 | 21 | 22 | serverPort = 9025 23 | lastTestExecution = None 24 | 25 | 26 | def outputRedirect(func): 27 | @functools.wraps(func) 28 | def wrapped(*args,**kwargs): 29 | backupStdOut = sys.stdout 30 | backupStdErr = sys.stderr 31 | sys.stdout = sys.__stdout__ 32 | sys.stderr = sys.__stdout__ 33 | try: 34 | return func(*args,**kwargs) 35 | finally: 36 | sys.__stdout__.flush() 37 | sys.stdout = backupStdOut 38 | sys.stderr = backupStdErr 39 | return wrapped 40 | 41 | def dropCachedImports(*packagesToUnload): 42 | ''' 43 | prepares maya to re-import 44 | ''' 45 | 46 | def shouldUnload(module): 47 | for packageToUnload in packagesToUnload: 48 | if module.startswith(packageToUnload): 49 | return True 50 | return False 51 | 52 | all_modules = [i for i in sys.modules.keys()] 53 | for i in all_modules: 54 | if shouldUnload(i): 55 | print("unloading module ", i) 56 | del sys.modules[i] 57 | 58 | 59 | 60 | currentTestSuite = random.randint(0,0xFFFF) 61 | 62 | @outputRedirect 63 | def launch(testSuiteId,sysPath,setupModuleName,moduleName,className,testMethodName): 64 | ''' 65 | this method gets called from within maya with current test class and method name 66 | ''' 67 | 68 | splitter = "-- TEST: "+className+"."+testMethodName 69 | splitter += '-'*(80-len(splitter))+"\n" 70 | sys.__stdout__.write(splitter) 71 | 72 | 73 | for sp in sysPath: 74 | if sp not in sys.path: 75 | sys.path.append(sp) 76 | 77 | # check if current test suite changed, and run setup fo this suite if needed 78 | suiteIdVar='mayatdd_currentTestSuite' 79 | if not cmds.optionVar(exists=suiteIdVar) or cmds.optionVar(q=suiteIdVar)!=testSuiteId: 80 | cmds.optionVar(iv=(suiteIdVar,testSuiteId)) 81 | 82 | setupModule = importlib.import_module(setupModuleName) 83 | reload(setupModule) 84 | 85 | if hasattr(setupModule, 'cleanUp'): 86 | print("running tests cleanup hook") 87 | setupModule.cleanUp() 88 | 89 | # reload modules 90 | print("running reloads") 91 | dropCachedImports(*setupModule.reloadModules) 92 | 93 | # run one-time setup.py tests 94 | if hasattr(setupModule, 'setup'): 95 | print("running tests setup hook") 96 | 97 | setupModule.setup() 98 | 99 | targetModule = importlib.import_module(moduleName) 100 | targetClass = getattr(targetModule, className) 101 | 102 | targetInstance = targetClass(testMethodName) 103 | 104 | def testExecution(): 105 | targetInstance.setUp() 106 | try: 107 | getattr(targetInstance, testMethodName)() 108 | finally: 109 | targetInstance.tearDown() 110 | 111 | testExecution() 112 | global lastTestExecution 113 | lastTestExecution = testExecution 114 | 115 | def serverHandler(request): 116 | def mainThreadHandler(request): 117 | try: 118 | launch(**request) 119 | return {'result':'success'} 120 | except Exception as e: 121 | import traceback;traceback.print_exc() 122 | #return {'result':'exception','exception': str(e)base64.b64encode(pickle.dumps(e, pickle.HIGHEST_PROTOCOL)).encode("utf-8"),'stackTrace':traceback.format_exc()} 123 | return {'result':'exception','exception': str(e),'stackTrace':traceback.format_exc()} 124 | 125 | from maya.utils import executeInMainThreadWithResult 126 | result = executeInMainThreadWithResult(mainThreadHandler,request) 127 | return result 128 | 129 | def mayaTest(setupModule): 130 | setupModule = sys.modules[setupModule] 131 | 132 | def decorator(cls): 133 | if not insideMaya: 134 | voidMethod = lambda *args,**kwargs:None 135 | setattr(cls,'setUp',voidMethod) 136 | setattr(cls, "tearDown", voidMethod) 137 | 138 | for methodName,method in list(inspect.getmembers(cls, lambda x: inspect.ismethod(x) or inspect.isfunction(x)))[:]: 139 | if not methodName.startswith("test"): 140 | continue 141 | 142 | if insideMaya: 143 | decorated = method 144 | 145 | # if test wrapper exists, use it for "decorated" value 146 | if hasattr(setupModule, 'testWrapper'): 147 | decorated = setupModule.testWrapper(method) 148 | 149 | else: 150 | def createDecoratedMethod(methodName,method): 151 | def decorated(*args,**kwargs): 152 | from . import server 153 | client = server.Client("127.0.0.1", serverPort) 154 | 155 | sysPath = [] if not hasattr(setupModule, 'sysPath') else setupModule.sysPath 156 | 157 | print("running {0}.{1}...".format(cls.__name__, methodName)) 158 | global currentTestSuite 159 | request = { 160 | 'testSuiteId': currentTestSuite, 161 | 'sysPath': sysPath, 162 | 'setupModuleName': setupModule.__name__, 163 | 'moduleName': cls.__module__, 164 | 'className': cls.__name__, 165 | 'testMethodName': methodName 166 | } 167 | 168 | response = client.send(request) 169 | 170 | if response['result']=='exception': 171 | raise Exception(response['stackTrace']) 172 | 173 | print("done executing", cls.__name__ + '.' + methodName) 174 | 175 | return wraps(method)(decorated) 176 | decorated = createDecoratedMethod(methodName, method) 177 | setattr(cls,methodName,decorated) 178 | 179 | return cls 180 | return decorator -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | Copyright 2015 Viktoras Makauskas 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. 191 | 192 | --------------------------------------------------------------------------------