Exemple #1
0
 def test_simple(self):
     c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
         [3, 1, 2]])
     self.repo.refs[b"HEAD"] = c3.id
     outstream = StringIO()
     porcelain.show(self.repo.path, objects=[c3.id], outstream=outstream)
     self.assertTrue(outstream.getvalue().startswith("-" * 50))
Exemple #2
0
    def test_commit_no_parent(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        self.repo.object_store.add_objects([(a, None), (ta, None), (ca, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[ca.id], outstream=outstream)
        self.assertMultiLineEqual(
            outstream.getvalue(), """\
--------------------------------------------------
commit: 344da06c1bb85901270b3e8875c988a027ec087d
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git /dev/null b/somename
new mode 100644
index 0000000..ea5c7bf 100644
--- /dev/null
+++ b/somename
@@ -0,0 +1 @@
+The Foo
""")
Exemple #3
0
    def test_commit_with_change(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        b = Blob.from_string(b"The Bar\n")
        tb = Tree()
        tb.add(b"somename", 0o100644, b.id)
        cb = make_commit(tree=tb.id, parents=[ca.id])
        self.repo.object_store.add_objects([(a, None), (b, None), (ta, None),
                                            (tb, None), (ca, None),
                                            (cb, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[cb.id], outstream=outstream)
        self.assertMultiLineEqual(
            outstream.getvalue(), """\
--------------------------------------------------
commit: 2c6b6c9cb72c130956657e1fdae58e5b103744fa
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git a/somename b/somename
index ea5c7bf..fd38bcb 100644
--- a/somename
+++ b/somename
@@ -1 +1 @@
-The Foo
+The Bar
""")
Exemple #4
0
    def test_commit_no_parent(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        self.repo.object_store.add_objects([(a, None), (ta, None), (ca, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[ca.id], outstream=outstream)
        self.assertMultiLineEqual(outstream.getvalue(), """\
--------------------------------------------------
commit: 344da06c1bb85901270b3e8875c988a027ec087d
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git /dev/null b/somename
new mode 100644
index 0000000..ea5c7bf 100644
--- /dev/null
+++ b/somename
@@ -0,0 +1 @@
+The Foo
""")
Exemple #5
0
    def test_commit_with_change(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        b = Blob.from_string(b"The Bar\n")
        tb = Tree()
        tb.add(b"somename", 0o100644, b.id)
        cb = make_commit(tree=tb.id, parents=[ca.id])
        self.repo.object_store.add_objects(
            [(a, None), (b, None), (ta, None), (tb, None),
             (ca, None), (cb, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[cb.id], outstream=outstream)
        self.assertMultiLineEqual(outstream.getvalue(), """\
--------------------------------------------------
commit: 2c6b6c9cb72c130956657e1fdae58e5b103744fa
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git a/somename b/somename
index ea5c7bf..fd38bcb 100644
--- a/somename
+++ b/somename
@@ -1 +1 @@
-The Foo
+The Bar
""")
Exemple #6
0
 def test_blob(self):
     b = Blob.from_string(b"The Foo\n")
     self.repo.object_store.add_object(b)
     outstream = StringIO()
     porcelain.show(self.repo.path, objects=[b.id], outstream=outstream)
     self.assertEqual(outstream.getvalue(), "The Foo\n")
Exemple #7
0
 def run(self, args):
     opts, args = getopt(args, "", [])
     porcelain.show(".", args)
Exemple #8
0
 def run(self, argv):
     parser = argparse.ArgumentParser()
     parser.add_argument('objectish', type=str, nargs='*')
     args = parser.parse_args(argv)
     porcelain.show(".", args.objectish or None)
def main(appliances=[],
         credentials=[],
         timeout=120,
         no_check_hostname=False,
         base_dir=default_base_dir,
         comment=default_comment,
         page=False,
         no_highlight_diff=False):
    """
    track_autoconfig.py

    Description:

    Store persisted domain configuration in a local git repository
    for auditing purposes.
    
    Usage:
        
        :::bash
        $ mast contrib/track_autoconfig.py --appliances <HOSTNAMES> --credentials <USER:PASS> --base-dir tmp/config

    Parameters:
    
    * `-a, --appliances` - The hostname(s), ip addresse(s), environment name(s)
    or alias(es) of the appliances you would like to affect. For details
    on configuring environments please see the comments in
    `environments.conf` located in `$MAST_HOME/etc/default`. For details
    on configuring aliases please see the comments in `hosts.conf` located
    in `$MAST_HOME/etc/default`.
    * `-c, --credentials`: The credentials to use for authenticating to the
    appliances. Should be either one set to use for all appliances
    or one set for each appliance. Credentials should be in the form
    `username:password` and should be provided in a space-seperated list
    if multiple are provided. If you would prefer to not use plain-text
    passwords, you can use the output of
    `$ mast-system xor <username:password>`.
    * `-t, --timeout`: The timeout in seconds to wait for a response from
    an appliance for any single request. __NOTE__ Program execution may
    halt if a timeout is reached.
    * `-n, --no-check-hostname`: If specified SSL verification will be turned
    off when sending commands to the appliances.
    * `-b, --base-dir`: The base directory where to store the downloaded
    files. Files will actually be stored in a subdirectory of `base_dir`
    named after the hostname in the form of `base_dir/<hostname>`    
    * `-p, --page`: If specified, page the output when too long to display
    at once
    * `-N, --no-highlight-diff`: If specified, the output of the diff will
    be syntax-highlighted
    """
    base_dir = os.path.abspath(base_dir)
    if not os.path.exists(base_dir):
        os.makedirs(base_dir)
    try:
        repo = git.Repo(base_dir)
        first_sha1 = repo.head()
        print first_sha1
    except NotGitRepository:
        print "Initializing git repository"
        git.init(base_dir)
        git.add(base_dir)
        first_sha1 = git.commit(base_dir, message="Initial Commit")
        print first_sha1
    except KeyError:
        git.add(base_dir)
        git.commit(base_dir, message="Initial Commit")
    print
    pull_autoconfig(appliances=appliances,
                    credentials=credentials,
                    timeout=timeout,
                    no_check_hostname=no_check_hostname,
                    base_dir=base_dir)
    git.add(base_dir)
    print git.status(base_dir)
    second_sha1 = git.commit(base_dir, message=comment)
    print second_sha1
    print "\n\nDIFF\n\n"
    
    tmp = StringIO()
    git.show(base_dir, outstream=tmp)
    tmp.seek(0)

    if no_highlight_diff:
        out = tmp.read()
    else:
        out = highlight(tmp.read(), DiffLexer(), TerminalFormatter())

    if page:
        pprint.page(out)
    else:
        print out
def main(appliances=[],
         credentials=[],
         timeout=120,
         no_check_hostname=False,
         base_dir=default_base_dir,
         comment=default_comment,
         persisted=False,
         recursive=False,
         no_strip_timestamp=False,
         page=False):
    """
    track_getconfig.py

    Description:

    Store running or persisted domain configuration in a local git
    repository for auditing purposes.

    Usage:

        :::bash
        $ mast contrib/track_getconfig.py --appliances <HOSTNAMES> --credentials <USER:PASS> --base-dir tmp/config

    Parameters:

    * `-a, --appliances` - The hostname(s), ip addresse(s), environment name(s)
    or alias(es) of the appliances you would like to affect. For details
    on configuring environments please see the comments in
    `environments.conf` located in `$MAST_HOME/etc/default`. For details
    on configuring aliases please see the comments in `hosts.conf` located
    in `$MAST_HOME/etc/default`.
    * `-c, --credentials`: The credentials to use for authenticating to the
    appliances. Should be either one set to use for all appliances
    or one set for each appliance. Credentials should be in the form
    `username:password` and should be provided in a space-seperated list
    if multiple are provided. If you would prefer to not use plain-text
    passwords, you can use the output of
    `$ mast-system xor <username:password>`.
    * `-t, --timeout`: The timeout in seconds to wait for a response from
    an appliance for any single request. __NOTE__ Program execution may
    halt if a timeout is reached.
    * `-n, --no-check-hostname`: If specified SSL verification will be turned
    off when sending commands to the appliances.
    * `-b, --base-dir`: The base directory where to store the downloaded
    files. Files will actually be stored in a subdirectory of `base_dir`
    named after the hostname in the form of `base_dir/<hostname>`
    * `-p, --persisted`: If specified, the persisted configuration will
    be retrieved as opposed to the running configuration (which is the
    default)
    * `-r, --recursive`: If specified, the configuration will be retrieved
    recursively to the extent of the facilities provided by DataPower
    * `-N, --no-strip-timestamp`: If specified, the timestamp will not be
    stripped from the XML document, This is done because we are tracking
    this information with git and stripping this out allows us to alert
    on any changes in the repository as opposed to special-casing the
    difference in timestamp.
    * `-P, --page`: If specified, page the output when too long to display
    at once
    """
    base_dir = os.path.abspath(base_dir)
    if not os.path.exists(base_dir):
        os.makedirs(base_dir)
    try:
        repo = git.Repo(base_dir)
        repo.head()
    except NotGitRepository:
        print "Initializing git repository"
        git.init(base_dir)
        git.add(base_dir)
        git.commit(base_dir, message="Initial Commit")
    except KeyError:
        git.add(base_dir)
        git.commit(base_dir, message="Initial Commit")

    check_hostname = not no_check_hostname
    env = datapower.Environment(appliances,
                                credentials,
                                timeout=timeout,
                                check_hostname=check_hostname)

    for appliance in env.appliances:
        appliance_directory = os.path.join(base_dir, appliance.hostname)
        if not os.path.exists(appliance_directory):
            os.mkdir(appliance_directory)
        for domain in appliance.domains:
            config = appliance.get_config(domain=domain,
                                          recursive=recursive,
                                          persisted=persisted)

            config = config.pretty
            if no_strip_timestamp:
                pass
            else:
                config = re.sub(r"^.*?<dp:timestamp>.*?</dp:timestamp>.*?$",
                                r"",
                                config,
                                flags=re.MULTILINE)

            filename = os.path.join(appliance_directory,
                                    "{}.xml".format(domain))
            with open(filename, "wb") as fout:
                fout.write(config)

    git.add(base_dir)
    print git.status(base_dir)
    git.commit(base_dir, message=comment)

    tmp = StringIO()
    git.show(base_dir, outstream=tmp)
    tmp.seek(0)
    out = highlight(tmp.read(), DiffLexer(), TerminalFormatter())
    if page:
        pprint.page(out)
    else:
        print out
Exemple #11
0
except Exception, e:
    import traceback
    stack = traceback.format_exc()

from dulwich import porcelain

scriptDir = sys.path[0]
repoPath = os.path.abspath(os.path.join(scriptDir, '..', '..', REPOSITORY))

print >> sys.stderr, "repo path: " + str(repoPath)

try:  #try to run a command
    if command == "init":
        porcelain.init(repoPath)
        porcelain.show(repoPath)
        with open(repoPath + '/.gitignore', 'w') as f:
            f.write('local/\n')
            f.write('*.sw?\n')
            f.close
    elif command == "ls":
        print "x,type,hash,path"
        porcelain.ls_tree(repoPath)
        #orcelain.show('..')
    elif command == "add":
        if paths == '':
            porcelain.add(repoPath)  # file(s) to add, defaults to app name
        else:
            porcelain.add(repoPath, paths)
        print "next steps:\nrun '|git status' to show what is ready to commit etc and '|git commit' to commit"
    elif command == "commit":
def main(appliances=[],
         credentials=[],
         timeout=120,
         no_check_hostname=False,
         base_dir=default_base_dir,
         comment=default_comment,
         persisted=False,
         recursive=False,
         no_strip_timestamp=False,
         page=False):
    """
    track_getconfig.py

    Description:

    Store running or persisted domain configuration in a local git
    repository for auditing purposes.
    
    Usage:
        
        :::bash
        $ mast contrib/track_getconfig.py --appliances <HOSTNAMES> --credentials <USER:PASS> --base-dir tmp/config

    Parameters:
    
    * `-a, --appliances` - The hostname(s), ip addresse(s), environment name(s)
    or alias(es) of the appliances you would like to affect. For details
    on configuring environments please see the comments in
    `environments.conf` located in `$MAST_HOME/etc/default`. For details
    on configuring aliases please see the comments in `hosts.conf` located
    in `$MAST_HOME/etc/default`.
    * `-c, --credentials`: The credentials to use for authenticating to the
    appliances. Should be either one set to use for all appliances
    or one set for each appliance. Credentials should be in the form
    `username:password` and should be provided in a space-seperated list
    if multiple are provided. If you would prefer to not use plain-text
    passwords, you can use the output of
    `$ mast-system xor <username:password>`.
    * `-t, --timeout`: The timeout in seconds to wait for a response from
    an appliance for any single request. __NOTE__ Program execution may
    halt if a timeout is reached.
    * `-n, --no-check-hostname`: If specified SSL verification will be turned
    off when sending commands to the appliances.
    * `-b, --base-dir`: The base directory where to store the downloaded
    files. Files will actually be stored in a subdirectory of `base_dir`
    named after the hostname in the form of `base_dir/<hostname>`    
    * `-p, --persisted`: If specified, the persisted configuration will
    be retrieved as opposed to the running configuration (which is the
    default)
    * `-r, --recursive`: If specified, the configuration will be retrieved
    recursively to the extent of the facilities provided by DataPower
    * `-N, --no-strip-timestamp`: If specified, the timestamp will not be
    stripped from the XML document, This is done because we are tracking
    this information with git and stripping this out allows us to alert
    on any changes in the repository as opposed to special-casing the
    difference in timestamp.
    * `-P, --page`: If specified, page the output when too long to display
    at once
    """
    base_dir = os.path.abspath(base_dir)
    if not os.path.exists(base_dir):
        os.makedirs(base_dir)
    try:
        repo = git.Repo(base_dir)
        repo.head()
    except NotGitRepository:
        print "Initializing git repository"
        git.init(base_dir)
        git.add(base_dir)
        git.commit(base_dir, message="Initial Commit")
    except KeyError:
        git.add(base_dir)
        git.commit(base_dir, message="Initial Commit")
    
    check_hostname = not no_check_hostname
    env = datapower.Environment(appliances,
                                credentials,
                                timeout=timeout,
                                check_hostname=check_hostname)

    for appliance in env.appliances:
        appliance_directory = os.path.join(base_dir, appliance.hostname)
        if not os.path.exists(appliance_directory):
            os.mkdir(appliance_directory)
        for domain in appliance.domains:
            config = appliance.get_config(domain=domain,
                                          recursive=recursive,
                                          persisted=persisted)

            config = config.pretty
            if no_strip_timestamp:
                pass
            else:
                config = re.sub(r"^.*?<dp:timestamp>.*?</dp:timestamp>.*?$",
                                r"",
                                config,
                                flags=re.MULTILINE)

            filename = os.path.join(appliance_directory,
                                    "{}.xml".format(domain))
            with open(filename, "wb") as fout:
                fout.write(config)

    git.add(base_dir)
    print git.status(base_dir)
    git.commit(base_dir, message=comment)
    
    tmp = StringIO()
    git.show(base_dir, outstream=tmp)
    tmp.seek(0)
    out = highlight(tmp.read(), DiffLexer(), TerminalFormatter())
    if page:
        pprint.page(out)
    else:
        print out
def main(appliances=[],
         credentials=[],
         timeout=120,
         no_check_hostname=False,
         base_dir=default_base_dir,
         comment=default_comment,
         page=False,
         no_highlight_diff=False):
    """
    track_autoconfig.py

    Description:

    Store persisted domain configuration in a local git repository
    for auditing purposes.

    Usage:

        :::bash
        $ mast contrib/track_autoconfig.py --appliances <HOSTNAMES> --credentials <USER:PASS> --base-dir tmp/config

    Parameters:

    * `-a, --appliances` - The hostname(s), ip addresse(s), environment name(s)
    or alias(es) of the appliances you would like to affect. For details
    on configuring environments please see the comments in
    `environments.conf` located in `$MAST_HOME/etc/default`. For details
    on configuring aliases please see the comments in `hosts.conf` located
    in `$MAST_HOME/etc/default`.
    * `-c, --credentials`: The credentials to use for authenticating to the
    appliances. Should be either one set to use for all appliances
    or one set for each appliance. Credentials should be in the form
    `username:password` and should be provided in a space-seperated list
    if multiple are provided. If you would prefer to not use plain-text
    passwords, you can use the output of
    `$ mast-system xor <username:password>`.
    * `-t, --timeout`: The timeout in seconds to wait for a response from
    an appliance for any single request. __NOTE__ Program execution may
    halt if a timeout is reached.
    * `-n, --no-check-hostname`: If specified SSL verification will be turned
    off when sending commands to the appliances.
    * `-b, --base-dir`: The base directory where to store the downloaded
    files. Files will actually be stored in a subdirectory of `base_dir`
    named after the hostname in the form of `base_dir/<hostname>`
    * `-p, --page`: If specified, page the output when too long to display
    at once
    * `-N, --no-highlight-diff`: If specified, the output of the diff will
    be syntax-highlighted
    """
    base_dir = os.path.abspath(base_dir)
    if not os.path.exists(base_dir):
        os.makedirs(base_dir)
    try:
        repo = git.Repo(base_dir)
        first_sha1 = repo.head()
        print first_sha1
    except NotGitRepository:
        print "Initializing git repository"
        git.init(base_dir)
        git.add(base_dir)
        first_sha1 = git.commit(base_dir, message="Initial Commit")
        print first_sha1
    except KeyError:
        git.add(base_dir)
        git.commit(base_dir, message="Initial Commit")
    print
    pull_autoconfig(appliances=appliances,
                    credentials=credentials,
                    timeout=timeout,
                    no_check_hostname=no_check_hostname,
                    base_dir=base_dir)
    git.add(base_dir)
    print git.status(base_dir)
    second_sha1 = git.commit(base_dir, message=comment)
    print second_sha1
    print "\n\nDIFF\n\n"

    tmp = StringIO()
    git.show(base_dir, outstream=tmp)
    tmp.seek(0)

    if no_highlight_diff:
        out = tmp.read()
    else:
        out = highlight(tmp.read(), DiffLexer(), TerminalFormatter())

    if page:
        pprint.page(out)
    else:
        print out