0

I am trying to build a script that generates Artifactory queries for an automation task.

An AQL query would look like the one below. For each image block, there are 2 curly braces followed by a comma, except after the last image block which is important.

Trying to make the script loop through "images.txt" to get the image names from each line and populate the query. The number of images will likely change.

**items.find({
    "$and": [
        {
            "repo": {
                "$eq": "docker-repository-name"
            }
        },

        {
            "$or": [**

            {
                    "path": {
                        "$match": "Image from file"
                    }
                },

                {
                    "path": {
                        "$match": "Image from file"
                    }
                },

                {
                    "path": {
                        "$match": "Image from file"
                    }
                }

}
                }
            ]
        }
    ]
})

I tried using a code block to write the actual code:

code_block = """
    
    {
       "path": {"$match":
    
"""

Then tried to loop through the file but this is just reading in the image names and adding a comma to the end of each line.

def generate_aql_from_text(text_file_path, aql_file_path):
    """Generates an AQL file from an external text file."""

    with open(text_file_path, 'r') as text_file, \
            open(aql_file_path, 'w') as aql_file:

        for line in text_file:
            query = line.strip()
            if query:  # Skip empty lines
                aql_file.write(query + ';\n')

if __name__ == "__main__":
    text_file_path = "images.txt"  # Replace with your text file path
    aql_file_path = "output.aql"  # Replace with your desired AQL file path

    generate_aql_from_text(text_file_path, aql_file_path)
1
  • The code you provided does not work as print(line_1) and print(line_2) are never defined. Please provide a minimal reproducible example with an example input and the corresponding expected output. Commented Dec 17, 2024 at 8:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.