specifying python environment variables for ant - python

Update: Forgot that sysproperty is only for java.
<target name="uploadFile">
<pathconvert property="orchestration.properties" refid="orch.config" />
<exec executable="python" failonerror="true">
<env key="PYTHONPATH" value="${basedir}/lib/python"/>
<arg value="${basedir}/upload.py"/>
<arg value="${basedir}/file.txt"/>
</exec>
</target>
Inside the lib/python directory is a custom python package i want to include when ant runs the exe.
How do I do that? It's not in python, so I can't add it to the path.

Right, I've solved this. Python path works, but I forgot to set new environment. If you don't set a new environment, it automatically reverts back to the old one.
If you ever want to run a python command from ant, but have modules in your basedir, and not the python directory, this is how you do it.
<target name="uploadFile">
<property environment="env"/>
<pathconvert property="orchestration.properties" refid="orch.config" />
<exec executable="python" failonerror="true" **newenvironment="true"**>
<env key="PYTHONPATH" value="${basedir}/lib/python"/>
<arg value="${basedir}/upload.py"/>
<arg value="${basedir}/test1.txt"/>
</exec>
</target>

Related

python copy picture files based on xml files

I want to write a python script to rename pictures with a templated folder structure.
The script should go through a bunch of xml files and pictures and find matches between the picture and the a node in one of the xml files.
Here is a small excerpt from one of the xml files, how they could look like:
<Data Date="2023-01-27">
<CONT FROM="2517817" TILL="2516239" STATION_A="40" STATION_B="140" />
<Alocation ZENDI="020000" Class="G" Number="8095" Location="R" L="1" />
<Pictures>
<B Nr="1" D="B1_3U00_002163.jpg" Station="80" A="142" />
<B Nr="2" D="B2_3U00_002163.jpg" Station="80" A="142" />
<B Nr="3" D="B3_3U00_002163.jpg" Station="80" A="142" />
</Pictures>
</Data>
When I have a match with the picture "B1_3U00_002163.jpg" it should copy this picture like that:
c:\temp\pictures\G8095\2517817_2516239_100_40_140\27.01.2023\placeholder\R\1\80.jpg
visualization of my task
and the other pictures files should be copied like so:
c:\temp\pictures\G8095\2517817_2516239_100_40_140\27.01.2023\placeholder\R\2\80.jpg
c:\temp\pictures\G8095\2517817_2516239_100_40_140\27.01.2023\placeholder\R\3\80.jpg
Do you have recommendations/tips how to start this project? What libraries can i use for this? Any helpful links?
So far im in the process of collecting ideas. I don't expect anything, I'm greatful for any help.

Removing a particular node on a specific line for all .xml files in a folder

I would really appreciate if i can get help with this problem, I have got hundreds of .xml files in a folder lets say /annots, and each .xml has a node called <occluded>0</occluded> and I am basically trying to iterate through all the .xml files in the folder /annots and delete that node <occluded>0</occluded> from all of the files in the folder, or better still delete text from a particular line since the node <occluded>0</occluded>, appears on the same line for each file.
Heres what my .xml file looks like:
`
<annotation>
<folder></folder>
<filename>Glass217_jpg.rf.92a572df568fd3d2ce118bfb5ffa6cb5.jpg</filename>
<path>Glass217_jpg.rf.92a572df568fd3d2ce118bfb5ffa6cb5.jpg</path>
<source>
<database>roboflow.ai</database>
</source>
<size>
<width>640</width>
<height>640</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>Glass</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<occluded>0</occluded>
<bndbox>
<xmin>55</xmin>
<xmax>372</xmax>
<ymin>248</ymin>
<ymax>406</ymax>
</bndbox>
</object>
</annotation>
`
I havent been able to try anything else, as I am not sure there is any tool to help me with this. I am also expecting the file names to remain the same when the node has been deleted for each
If you want to do it by line number, you can simply use sed:
sed -i.bkp -e'19d' annots/*.xml
Will delete line 19 on all *.xml files in folder annots. The original files will be retained with .bkp suffix.
If you cannot rely on the line number, but want to parse the XML and delete the tag, xmlstarlet is your friend. Unfortunately, xmlstarlet does not have any in-place-editing option, so you need to run a loop:
for FILE in annots/*.xml; do
mv $FILE $FILE.bkp
xmlstarlet ed -d '//occluded' $FILE.bkp >$FILE
done

Python Script has no effect on Apache Ant Build

I have an ant build file: build.xml, with an existing build target: Rebuild-ALL. that I run from ant eclipse plugin.
The build file contains paths referenced from another file: file.def.
I would like to create a new build target that builds from another path.
I started by doing the following:
Creating a python script that modifies the path in file.def.
I added this script to a target: Change-Paths.
I created a copy of the existing build target: Copy1-Rebuild-ALL
I added my Change-Paths target to the depends of the Copy-Rebuild-ALL.
I also created a second python script to revert the path change in file.def and repeated steps 2 to 4 to have another 2 targets: Revert-Paths and Copy2-Rebuild-ALL.
The problem is that the second build target still takes the path of the first build target even though I can see on my editor that the python script has successfully replaced the paths.
After executing the second target 3 consecutive times it works fine so is there maybe a refresh or a delay I can add to fix this ?
I tried using ant calls instead of depends but still the same issue occurs.
I am still new to ant and build files in general so let me know if there's a better way to do this.
Here is a an example to my build.xml file:
<project name="Build" xmlns:if="ant:if" xmlns:unless="ant:unless" default="REBUILD_ALL" basedir="${ant.file}/../../../..">
<property file="${TOOLS.PATH}/Compiler/file.def" />
<property name="COMPILER" value="${VENDOR.COMPILER}" />
<target name="Change-Paths">
<exec executable="${python.exe}" dir="${basedir}" failonerror="true" inputstring="${TOOLS.PATH}/Compiler/file.def">
<arg line="${SCRIPTS.PATH}/Change_Paths.py" />
</exec>
</target>
<target name="Copy1-Rebuild-ALL" description="Build all files from the project to output executable files" depends="Change-Paths, BuildMakesParallel, LINK_ALL">
</target>
<target name="Revert-Paths">
<exec executable="${python.exe}" dir="${basedir}" failonerror="true" inputstring="${TOOLS.PATH}/Compiler/file.def">
<arg line="${SCRIPTS.PATH}/Revert_Paths.py" />
</exec>
</target>
<target name="Copy2-Rebuild-ALL" description="Build all files from the project to output executable files" depends="Revert-Paths, BuildMakesParallel, LINK_ALL">
</target>
</project>
Also here is an example to file.def:
VENDOR_PATH = c:/VENDOR/toolchains/compiler_name/v1
VENDOR.COMPILER = ${VENDOR_PATH}/bin/compiler_name-gcc.exe
I permanently added the new path in file.def and added a new property in build.xml to hold this path as follows:
VENDOR_PATH_2 = c:/VENDOR/toolchains/compiler_name/v2
VENDOR.COMPILER_2 = ${VENDOR_PATH_2}/bin/compiler_name-gcc.exe
Now the python script will only replace the property name in the macro that compiles files in the build target and it works as expected.

Create a file with maven

I am using maven to generate some protobuf python code but it erases the init.py every time.
I was wondering if maven had a tool to create a blank init.py so that I do not need to create it manually every single time.
(Maybe a copy from a different init.py)
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<checkStaleness>true</checkStaleness>
<staleMillis>10000</staleMillis>
<protocExecutable>${protocLocation}</protocExecutable>
</configuration>
<executions>
<execution>
<id>compile protobuf</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
<goal>test-compile-python</goal>
</goals>
</execution>
<execution>
<id>compile-python</id>
<phase>initialize</phase>
<goals>
<goal>compile-python</goal>
</goals>
<configuration>
<checkStaleness>false</checkStaleness>
<outputDirectory>${pythonOutputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This is the plugin that generates the code and removes the init.py
Note that I set checkstaleness to false. This means it will write protobuf files even if they are not older than a certain time. This is because it was not detecting changes and not writing them out.
EDIT:
The solution was found here:
https://github.com/xolstice/protobuf-maven-plugin/issues/9
Instead of creating a new file. I instead just didn't delete it.
(for anyone else wanting to create a file through maven... keep searching!)
The solution was found here:
https://github.com/xolstice/protobuf-maven-plugin/issues/9
Instead of creating a new file. I instead just didn't delete it.
(for anyone else wanting to create a file through maven... keep searching!)

How put baseurl as a parametrs in selenium tests

I have 1 file with selenium tests, with baseURL in it. So now i need to find a way to launch this tests from console with URL as a parametr.
I have one local, developer and production server, so i want to run this tests without hardcode baseURL in it.
Is anyone one have some idea for this?
Waiting for your answers :3
Yes, you can create one Environment file any format would do (.xml, .xlsx, .properties etc).
Then you just mention environment specific details and parse the file. Its better if you use .xml format. In this way you can create node like configuration with parent being the environment name. In this way you can add any number of configuration for different servers.
Something like:-
XML Format:-
<environments>
<environment id="local">
<parameter>
<name>host</name>
<value>LocalURL</value>
</parameter>
</environment>
<environment id="development">
<parameter>
<name>host</name>
<value>DevelopmentURL</value>
</parameter>
</environment>
<environment id="production">
<parameter>
<name>host</name>
<value>ProductionURL</value>
</parameter>
</environment>
</environments>
Properties File Format:-
localUrl = http://local.com
developmentUrl = http://development.com
productionUrl = http://production.com
Any format you can use and write a code to parse it.

Categories

Resources