One of my new years resolutions this year was to try and replace bash scripting with python in some of my projects. The reasons for this include the ability to use objects to group parameters together.
At today’s (Jan 19, 2025) Python over Coffee meetup, Ricardo suggested that I look at the plumbum library as a tool to help make that transition. In my first hack at using it, I came across an issue: I need to read in environment variables.
Author Archives: Adam Young
Setting column width on Apache default index pages
If you can’t read the text on the default index page of your Apache HTTPD server, you can make it larger with a .htaccess file.
cat .htaccess
IndexOptions NameWidth=80
If you put this in the root of the troublesome tree, it will server for that directory and all directories below it.
GitPython do two files differ in different branches
Not quite as succinct as I would have liked, but this does work. This is a one liner in Bash, and I had hoped to do it with a single python call once I had the repo object established. In general, diffs are not simple to do on blob objects. I had trouble using the difflib and set approaches to diffing the two files, possibly due to the fact that I was originally not decoding the streams. Thus all the splitlines work probably can be simplified.
Continue readingBuilding the Linux Kernel on one machine, deploying on another
Software Development flow is an elusive beast, easily frightened away. The easiest way to lose the flow is to have a long development cycle. Building the entire Linux Kernel takes time. If you are developing a single driver that can be built as a stand alone module, you do not want to have to rebuild the entire Kernel each time you make a change to that module. If that module crashes the machine when it runs into an error, you do not want to have to wait for that machine to reboot before digging in to the debugging process.
These two guidelines lead to a pattern of building on one machine and deploying on another. Here is one way to go about this process.
Long Refactoring: Resetting the class model
With the inclusion of the Generators, the main functions seem to be in the right shape. What seems off is the naming of things. For example, we have a couple functions that take a parameter named “board” but it turns out they mean different things. The names of classes do not seem to align with what they are doing.
Lets continue with the renaming of things and see where it leads us.
But first: we can remove the exceptions to the flake8 testing, and, with the removal of some white space, we can run with all the pep8 rules intact. Now, on to renaming.
I am not going to go through each commit, but will try to provide enough context so you could follow the logic in the commits in github.
This is the last article in my Long Refactoring series. You can read the first article here.
Continue readingRust and Dependency Injection.
For years now I have wanted to write a DI framework for Rust like I wrote for C++:
http://adam.younglogic.com/2008/07/dependency-injection-in-c/
However, I have not been able to wrap my head around how to do that. The problem is that the DI framework, which both creates and shares the instances, will come in to conflict with the borrow checker.
Long Refactoring: Generators
While the main solving function is now cleaned up, I am not very happy with the code that checks the validation on each cell.
I am not going to go through each step here, as the pattern is well established now. Pull out of the function anything that is a distractor. Once you have the heart of the algorithm, clean it up. Then put things back together.
Continue readingGetting a File from gitlab using a TOKEN
I work on a system in our lab that I connect to via SSH. Fetching a file via the web and pushing it to this machine is quite slow, and I want to pull on this machine directly. The trick to make this work is to use a TOKEN from gitlab and oauth2 as the username portion of the URL. For example
curl -O https://oauth2:$CI_JOB_TOKEN@gitlab.com/api/v4/projects/$PROJECT_ID/packages/generic/$PROJECT_NAME/$PROJECT_VERSION/$FILE
The CI_JOB_TOKEN must be set to a token that has appropriate permissions on your project. Most of the values I wrote as envvars could be copy-pasted from the gitlab packages link on the web.
Adding stable to a blobless clone
We regularly sync various git repos from upstream to our company speicfic Linux repository. However, sometimes when working on a development machine, I need a branch from stable that we have not synced yet. If I did a blobless clone from our repository, doing a fetch from stable is going to pull over lots of blobs that I do not need.
Instead, I want to fetch just a specific tag. I can do this by adding the tag to the fetch command, and it will pull over only those blobs
xmllint for xpath
Beaker one liner using xmllint:
bkr job-results J:61 | xmllint --xpath /job/recipeSet/recipe/roles/role -
<role value="RECIPE_MEMBERS"/>
The dash at the end makes it read from stdin