Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use regex to extract pinned commits from moonraker.conf and reset repo's to the correct commit hashes during build in respective modules. #156

Open
miklschmidt opened this issue Oct 3, 2024 · 1 comment

Comments

@miklschmidt
Copy link
Member

miklschmidt commented Oct 3, 2024

The following somewhat janky regex should work

\[update_manager\s(?<module>\w+)]((?!\[)|(?!\n\n)\X)+pinned_commit:\s(?<commit>[[:xdigit:]]+)
@miklschmidt miklschmidt changed the title Use regex to extract pinned commits from moonraker.conf and reset repo's to the correct commit hashes. Use regex to extract pinned commits from moonraker.conf and reset repo's to the correct commit hashes during build in respective modules. Oct 3, 2024
@CrashTestCharlie
Copy link

What's the context for this regex?

Specifically,

  1. What environment does it run it?
  2. Does whatever is doing the calling know which repo it's trying to rebuild? (I would assume so, but need to check.)
  3. Could the caller call out to an external script with the repo name and path to the moonraker.conf file?

If 3, then a python script that reads the conf file and properly parses it could be a better solution.

Sample code would look something like this:

#! /usr/bin/env python3

import re
import configparser
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-r", "--repo", dest="repo")


def extract_commit(repo, file_name):
    section_name = "update_manager" + " " + repo
    config = configparser.ConfigParser()
    config.read(file_name)

    if section_name not in config.sections():
        return None

    if "pinned_commit" not in config[section_name]:
        return None

    return config[section_name]["pinned_commit"]


if __name__ == "__main__":
    (opts, args) = parser.parse_args()
    pin = extract_commit(opts.repo, args[0])
    if pin is None:
        exit(1)

    print(pin)

Result:

$ /tmp/regex.py -r KlipperScreen moonraker.conf
71eef9ee1f23aa4fd6b68169cfe5dd7908e478b2

or

$ /tmp/regex.py -r foo moonraker.conf
$ echo $?
1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants