My directory structure is --> test => [blueprint.yaml, scripts [python_script.py, sample.conf]] python_script.py would basically read default configurations from sample.conf and parse/do some string operations and generates a new conf file. But am not able to get the path of sample.conf as it keeps changing with every deployment. Example: ./tmp/cloudifyLookupYamls/archive1658295820027/extracted/script_plugin/scripts/sample.conf ./tmp/cloudifyLookupYamls/archive1658294160172/extracted/script_plugin/scripts/sample.conf ./tmp/cloudifyBrowseSources/script1658295889590/extracted/script_plugin/scripts/sample.conf
Below is the python script:
import configparser
from cloudify import ctx
from cloudify.state import ctx_parameters as inputs
import os
print("Path at terminal when executing this file") # this is /
print(os.getcwd() + "\n")
print("This file path, relative to os.getcwd()") # this is /tmp/ZMX3U/python_script.py
print(__file__ + "\n")
print("The directory is ")
print(os.path.dirname( __file__ )+ "\n") # this is /tmp/ZMX3U
parser = configparser.ConfigParser()
parser.read("sample.conf") # this is the problem, this file is not present at the place the script runs
configer = configparser.ConfigParser()
#parsing logic
with open(r"/tmp/new.conf", 'w+') as configfile:
configer.write(configfile, True)
I see that the script file is executed in a temporary directory /tmp/ZMX3U/. Please suggest on how I can access the sample.conf from my python_script.py
@Kasibak if you want to have access to any file associated inside the blueprint, you can check the documentation
https://docs.cloudify.co/latest/bestpractices/plugin-development/#downloading-resources-using-ctx-download-resource
so you would do
path = ctx.download_resource('sample.conf')
then you can do whatever you want with the file