コード例 #1
0
ファイル: git.py プロジェクト: rmatulat/nacl
def git(args, env={}):
    """
    The main git command wrapper

    Expects a list of args (e.g. ['diff']) and returns the git command output.
    Parameter env is used to append environment vars to ENV like a
    proxy setting.
    """

    user_config = get_users_nacl_conf()

    # We have to merge the os.environment and env, because we need HOME!
    env = merge_two_dicts(env, os.environ)

    # Any Proxy?
    try:
        proxy = user_config['proxy']
    except KeyError:
        proxy = False

    if proxy:
        env = merge_two_dicts(env, {'https_proxy': user_config['proxy']})

    p = Popen(['git'] + args, stdout=PIPE, stderr=PIPE, env=env)
    output, err = p.communicate()
    rc = p.wait()

    if err and rc != 0:
        raise GitCallError(err)

    # We are doing this because there might be umlauts in output that can not
    # be decoded to unicode (don't know why) and throwing errors like:
    # UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)
    # Decoding it like below makes the decorator convert the str successfully
    # to unicode.
    # Ugly hack, but I just don't get it right by now.
    # TODO: Unterstand str and unicode better
    return output.decode("utf-8")
コード例 #2
0
ファイル: test_nacl_base.py プロジェクト: rmatulat/nacl
 def test_get_users_nacl_conf_no_logging(self,
                                         os_mock,
                                         open_mock,
                                         json_mock):
     """ Catching an exception, print no logs"""
     self.assertFalse(get_users_nacl_conf(True))
コード例 #3
0
ファイル: test_nacl_base.py プロジェクト: rmatulat/nacl
 def test_get_users_nacl_conf(self, os_mock, open_mock, json_mock):
     """ get_users_nacl_conf() works fine """
     self.assertEqual("{'foo': 'bar'}", get_users_nacl_conf())