How to use variables of git submodule foreach in gitpython - python

Using gitpython, I would like to use repo.git.submodule('foreach', …) and get the variables available such as name, sm_path, displaypath, sha1 and toplevel as defined in the git documentation.
I couldn't find any documentation on gitpython and my understanding of the API is limited.

Thanks to stsewd reply on Github issue, one should write
repo = git.Repo('foo/bar')
for sub in repo.submodules:
pass
and the documentation: https://gitpython.readthedocs.io/en/stable/reference.html#git.repo.base.Repo.submodules

Related

Sphinx: reference special methods

Sphinx allows linking to external documentation (such as the standard library docs) via intersphinx.
Is it possible to link to the definition of special methods like __del__(), without just making a regular link?
Ok, so in my case, I just needed to link to the object.__del__ method:
:py:meth:`__del__() <object.__del__>`
To do this generically:
Use python -m sphinx.ext.intersphinx https://docs.python.org/3/objects.inv to get the inventory of the python docs. You're gonna want to pipe the output through less or grep or save it to a file
Search through the results for the thing you're looking for. For special methods, it'll probably be object.__spam__
Look at the section the thing is under, and add it to your rst

GitPython: how to commit updated submodule

I have been at this for hours now, and although I have a feeling I'm close I can't seem to figure this out.
I'm trying to make a script that takes a git repository, updates a submodule in that repository to a specified version, and commits that change.
What works:
I can find the repository, get the submodule and check out the commit I want.
What doesn't work:
I can't seem to add the updated submodule hash so I can commit it.
My Code:
repos = Repo('path/to/repos')
submodule = repos.submodule('submodule-name')
submodule.module().git.checkout('wanted commit')
diff = repos.index.diff(None)
At this point I can see the submodule-change. If I check sourcetree, I can see the changed submodule in the 'unstaged files'.
The thing is, I have no clue how to stage the change so I can commit it.
What I have tried:
If I commit using repos.index.commit(''), it creates an empty commit.
If I try to add the path of the submodule using repos.index.add([submodule.path]), all files in the submodule are added to the repository, which is definately not what I want.
If I try to add the submodule itself (which should be possible according to the docs) using repos.index.add([submodule]), nothing seems to happen.
There are two ways to add new submodule commits to the parent repository. One will use the git command directly, the other one will be implemented in pure-python.
All examples are based on the code presented in the question.
Simple
repos.git.add(submodule.path)
repos.index.commit("updated submodule to 'wanted commit'")
The code above will invoke the git command, which is similar to doing a git add <submodule.path> in a shell.
Pythonic
submodule.binsha = submodule.module().head.commit.binsha
repos.index.add([submodule])
repos.index.commit("updated submodule to 'wanted commit'")
The IndexFile.add(...) implementation adds whichever binsha it finds in the submodule object. This one would be the one in the parent repository's current commit, and not the commit that was checked out in the submodule. One can see the Submodule object as a singular snapshot of the submodule, which does not change, nor does not it know about changes to the submodule's repository.
In this case it seems easiest to just overwrite the binsha field of the submodule object to the one that is actually checked out in its repository, so adding it to the index will have the desired effect.

ServiceNow GlideRecord sysparm_query Python

Has anyone used the GlideRecord library for python? I can't seem to get it to perform some fairly basic functionality. I want to add a few sysparm_query parameters. This is just a code snippet, I had to manually edit it for security purposes. Hopefully I didn't introduce any typo errors.
for i in glide1, glide2:
i.set_credentials('xxxx', 'xxxx')
i.set_server("https://<instance>.service-now.com/")
i.addQuery("active", "true")
def getIncidents(glide1):
group = "mygroup"
glide1.addQuery('assignment_group', group)
print glide1.query_data['sysparm_query'] + '\n'
print glide1.getQuery()[50:] #just to avoid too much output
gives me the output:
active=true^assignment_group=mygroup
displayvalue=true&JSONv2&sysparm_record_count=100&sysparm_action=getRecords&sysparm_query=
I cannot get the query data to append. Perhaps I should look at doing the queries manually? Here is a link to the GlideRecord git:
https://github.com/bazizi/ServiceNow_GlideRecord_API/blob/master/GlideRecord/init.py
Cheers, Arthur
I just realized that the getQuery() member function I had defined only returned the base query URL (not including the query itself). I had initially added this function for testing purposes, and wrongfully added this to the documentation.
I just fixed this issue and committed to the GitHub repository. Please pull from the git repository again or if you installed using PIP, run the following commands to re-install it from scratch:
pip uninstall GlideRecord
pip install GlideRecord
In terms of setting the assignment group by name, however, I still need to find out how ServiceNow hashes the assignment_group, or if there is another way this query can be added; That is, I have no fix for now.
Thanks
Behnam

Subversion Get Text Status Data in Python Commit Hooks

I'm looking for a way to extend Python Commit Hooks such that I can ONLY find out all the files that were modified excluding all the revision properties changed.
Is there a SVN.Core or SVN.fs or another SVN import lib function that I could use?
I'm currently looking into
svn_fs_txn_prop
but haven't had much luck.
Thanks in Advance.
Using Subversion Core library in Python you can create a class to read through different Subversion Properties associated with a commit.
you can call something like:
changeCollector = svn.repos.ChangeCollector(self.fs_obj,self.fsroot,self.pool);
for path, change in changeCollector.changes.items():
# this is the property that i want
change.text_changed

CouchDB-Python: how to use “_show” and “_list” functions?

The python-couchdb package (used as import couchdb) provides a db.view() function to access a couchdb "_view", but how do you access a "_show" or "_list" function?
This was asked before (http://stackoverflow.com/questions/5491851/couchdb-and-python-how-to-use-show-and-list-functions) and 1 of the authors said that it was now included in the library, but he doesn't mention HOW to use it (db.show() doesn't work) and I can't find any documentation for it online.
Can anyone let me know the function/method - or - point me at a page that explains how to do it. I'm particularly interested in "_show".
Currently, you need to get couchdb-python from repository: there are implemented Database methods to call _show, _list and _update functions.

Categories