I want to use osmconvert to parse down the size of my diff files for just the area I'm interested in because osmconvert is way faster than osm2pgsql, which loads the data.
When I call the command using os.system() like such:
cmd = r"""c:\temp\osmconvert.exe 770.osc.gz -b=1,1,3,3 -o=extract.o5m"""
os.system(cmd)
I get osmconvert error: cannot open file
When I run the same exact command from my command prompt in Windows 7, it runs fine. What is python doing to prevent this function from running? The 770.osc.gz file lives in the same directory as osmconvert.exe and the output extract.05m should populate in the same directory as the osmconvert.exe exists.
If I put the command in a batch file, it works, but I want to use python to download the file from the server so I can automate the updates of the database.
Thank you
The 770.osc.gz file lives in the same directory as osmconvert.exe and the output extract.05m should populate in the same directory as the osmconvert.exe exists.
That's not what your code is saying. The code says "execute osmconvert.exe from inside c:\temp\ but read 770.osc.gz and write extract.o5m from the current working directory".
If you want everything to run inside c:\temp\ then you either have change to this directory before executing osmconvert or you have to preprend the path to every file you are passing to osmconvert.
Try this call instead:
cmd = r"""c:\temp\osmconvert.exe c:\temp\770.osc.gz -b=1,1,3,3 -o=c:\temp\extract.o5m"""
Related
I have a python script that points to some file names and log files and I have jenkins to run the script, when run locally from my system the code works fine.
The way I access my folders in python:
folder_artifacts_data = 'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Artifacts/'
path_to_log_file ='C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log'
but when I try to run the same using jenkins, I get the following error:
No such file or directory:
/opt/jenkins/workspace/confluencetest_scheduled/C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log
Now, I tried different file paths and used r-strings
folder_artifacts_data = r'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Artifacts/'
path_to_log_file =r'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log'
I see that jenkins has accepted the log file, because I see the logs written, but the moment it reaches folder_artifacts_data it throws the error that the file path do not exist.
Could someone help?
Update
Now I have added relative paths, like:
folder_artifacts_data0 = 'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Artifacts/'
folder_artifacts_data = os.path.relpath(folder_artifacts_data0)
path_to_log_file0 ='C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log'
path_to_log_file = os.path.relpath(path_to_log_file0)
that outputs paths like:
..............\Rhea\OneDrive -Area\Rhea\Metrics_Configuration\Artifacts
and
..............\Rhea\OneDrive -Area\Rhea\Metrics_Configuration\Logfiles\Logfile.log
this works well in my local, again I get
No such file or directory:
/opt/jenkins/workspace/confluencetest_scheduled/C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log while running from jenkins.
I'm implementing https://github.com/siedi/webpagetest-influxdb .While running the run-tests.sh shell script which takes URL(of a web page) as a a parameter and i want to pass a text file which takes login information.
As mentioned in - https://sites.google.com/a/webpagetest.org/docs/advanced-features/webpagetest-batch-processing-command-line-tool ,i tried to write my URL to an external file and used --urlfile=/foo/urls.txt (like sh run-tests.sh --urlfile=/foo/urls.txt) which is in Python.
Above method in SH is not seem to be working
Can anyone help me on how can i pass these two files along with sh command if its possible.
so i checked several other links with similar titles but, It couldn't solve my specific question. I'm trying to run a python file in notepad++ which is not a problem to me however, this file takes in a few things in order for it to compile. This is how I successfully run it in the command prompt.
python upload.py --file= "video path" --title= "title" --description= "testing"
My question is, how would i set these attributes in a different python file and then just call that file instead?
here is my code that i have in my new file
Thanks
enter image description here
enter image description here
You can use the subprocess module to do this. Following the example from the docs and the code you've listed:
import subprocess
result = subprocess.check_output('python upload.py --file="video path" --title="title" --description="testing"')
result will store any output from your command.
Note: if you're running in a windows environent, not linux, change the /usr/bin/python to python.
Maybe you can use subprocess to call your specific command.
In a separate file in the same folder, you can put a file like this:
import subprocess
subprocess.call("python upload.py --file= \"video path\" --title= \"title\" --description= \"testing\"")
And then you just call that file, and that's it...
Here is the code I have so far:
How can I make this program open another python file, using this method or similar (you have to open it from a variable)?
You can use exec function, for to execute an external script,
file = "test.py"
exec(open(file).read())
you get,
File Opened!
I spend a few hours writing a little script.
Basically what it does is create a new text file and fills it up with whatever.
I zip the text file --using zipfile-- and here's where my problem lies.
I want to run the Windows system command:
copy /b "imgFile.jpg" + "zipFile.zip" newImage.jpg
To merge the image "imgFile.jpg" and the zip "zipFile.zip".
So:
os.system("copy /b \"imgFile.jpg\" + \"zipFile.zip\" newImage.jpg")
When I run my script, it all seems to go fine.
But when it's done and I try to extract the 'newImage.jpg' file, it gives me:
The archive is either in unknown format or damaged
This ONLY happens when I run the system command within the script.
It works fine when I use the shell. It even works if I use a separate script.
I've double checked my zip file. Everything is in good shape.
Is there something I'm doing wrong? Something I'm not seeing?
Have you tried using shutil?
import shutil
shutil.copy(src, dst)
There may be a problem with the way Python is passing the arguments to the shell command. Try using subprocess.call. This method takes arguments as an array and passes them that way to the command:
import subprocess
subprocess.call(["copy", "/b", '"imgFile.jpg" + "zipFile.zip"', "newImage.jpg"])