示例#1
0
def git_version_info():
    try:
        from gitinfo import get_git_info
    except (ImportError, TypeError):
        return None

    commit = get_git_info()
    if not commit:
        return None

    message = commit["message"].split("\n")[0]

    return f"{commit['commit'][0:8]}: {message} @{commit['author_date']}"
 def get(self):
     self.set_status(200)
     self.response[
         'message'] = 'Welcome to the Erasmus+ DESQOL Authentication Server!'
     git_commit_hash = environ.get('GIT_COMMIT_HASH')
     if git_commit_hash:
         self.response['commit'] = git_commit_hash
     else:
         git_info = get_git_info()
         if git_info:
             self.response['commit'] = git_info['commit']
         else:
             self.response['commit'] = 'UNKNOWN'
     self.write_json()
示例#3
0
def get_platform_info():
    """Get information about the computer running this process"""

    if hasattr(os, 'sched_getaffinity'):
        accessible = len(os.sched_getaffinity(0))
    else:
        accessible = os.cpu_count()
    return {
        'git_commit': get_git_info()['commit'],
        'processor': platform.machine(),
        'python_version': platform.python_version(),
        'python_compiler': platform.python_compiler(),
        'hostname': platform.node(),
        'os': platform.platform(),
        'cpu_name': platform.processor(),
        'n_cores': os.cpu_count(),
        'accessible_cores': accessible,
    }
示例#4
0
 def test_has_git(self):
     ret = get_git_info()
     self.assertTrue("commit" in ret)
     self.assertTrue("message" in ret)
示例#5
0
 def test_packed(self):
     ret = get_git_info('../../c/git')
     self.assertTrue("commit" in ret)
     self.assertTrue("message" in ret)
示例#6
0
 def test_should_not_crash_with_emtpy_git_dir(self):
     # Create a dir named named empty_git and run git init there to test this
     if os.path.isdir("empty_git"):
         ret = get_git_info("empty_git")
         self.assertEqual(ret, None)
示例#7
0
 def test_should_work_with_relative_paths(self):
     # The parent directory should *not* have a git file
     # Should work with ..
     ret = get_git_info("..")
     self.assertEqual(ret, None)
示例#8
0
 def test_doesnot_have_git(self):
     # The parent directory should *not* have a git file
     ret = get_git_info(os.path.dirname(os.getcwd()))
     self.assertEqual(ret, None)
示例#9
0
 def test_has_gitdir(self):
     ret = get_git_info()
     self.assertTrue("gitdir" in ret)
     self.assertTrue(os.path.dirname(ret["gitdir"]) == os.getcwd())
示例#10
0
 def test_message_not_empty(self):
     ret = get_git_info()
     self.assertTrue(len(ret["message"]) > 0)
示例#11
0
def get_git_hash():
    info = gitinfo.get_git_info()
    return info["commit"], info["message"]