hubot script load yml file, dont work with relative path - node.js

I am building a hubot script and I want to load a yml file in it.
I am using the yamljs npm package to read the YAML file.
The problem is that it allways says "No such file or directory" error.
If i put the absolute path it works.
What I am missing?
I am loading the file like this:
feeds = YAML.load('../feeds.yml');
Here is my directory structure:

Where are you executing the script from? In node, path files in fs are relative to process.cwd().
Relative path to filename can be used, remember however that this path
will be relative to process.cwd().
Sources: http://nodejs.org/api/fs.html, https://stackoverflow.com/a/16730379/1007263
Therefore, if your script is in the same directory as feeds.yml, you should probably:
feeds = YAML.load('./feeds.yml');
Otherwise, there might be a bug in YAML. In this case, you can simply use path to deliver the absolute path directly.
path.resolve('../feeds.yml')
Source: http://nodejs.org/api/path.html#path_path_resolve_from_to

Related

Copying shell file to path

I'm new to WSL and Linux, but I'm trying to follow installation instructions for rhasspy (https://rhasspy.readthedocs.io/en/latest/installation/#windows-subsystem-for-linux-wsl). I have run the make install command successfully and the next step says I should copy rhasspy somewhere in my path but I can't quite figure out what copying to path means.
When installation is finished, copy rhasspy.sh somewhere in your PATH and rename it to rhasspy.
I added it to path but nothing changed so I was wondering if there is something I'm doing wrong. Right now when I run rhasspy on wsl it says rhasspy.sh: command not found. Any help would be really appreciated!
What it says is, put it in some place where the system will look for it when you type its name without full path in the shell.
There is an environment variable PATH that contains all those locations, separated by a :. (Check out echo $PATH.)
So, the author of these instructions leaves it up to you whether...
You want to copy the file to a location of your choice that is already in the PATH, such as /usr/local/bin or ~/bin.
Usually ~/bin is a good choice because it is per-user and doesn't pollute the system.
(Note that the directory ~/bin is added to the PATH by your .profile file only if it exists, so if you don't have this directory yet and create it now, you need to start a new login shell or run . ~/.profile1 before you can use it.)
- OR -
You want to create a new directory specifically for this application (say for example ~/opt/rhasspy) and append that directory to the PATH variable.
This can be done by adding the line export PATH=$PATH:~/opt/rhasspy to your ~/.profile file. Then, start a new login shell or reload the file using . ~/.profile1 for the changes to take effect.
If the directory in which this file is currently located is OK for you to keep permanently, then you can also just add that directory to the PATH instead of creating a new one.
Note: The PATH always contains directory paths in which the shell will look for executable files. It does not contain the actual file paths!
1: Yes, technically it is "cleaner" to log into a new shell or to run that one export statement manually instead of using . ~/.profile because the latter will apply things a second time that were already done before, so for example it can end up with the same directory in the PATH multiple times in the current session. In most cases that is fine though.
PATH is an environment variable. When you launch env, you see the list of known environment variables on your system.
In order to add something to your PATH variable, you need to take the variable, add the mentioned directory (preceeded by a semi-colon, most probably, as a separator) and store this again as the PATH variable. This can be done as follows (own example):
export PATH=$PATH:/home/this_user
the "PATH" it is referring to in linux is just inside the folder called /usr/bin. when you type a command into the terminal it looks for a program with that name inside the location. im not sure if this is the PATH you are looking for but hope it helps

How do i formulate file path for testsettings on the Runsettings file parameter <SettingsFile>

Whats the proper way to form relative file path/ or file path for the runsettings parameter
<SettingsFile>xxxxxAutomation.testsettings</SettingsFile>
In my local environment this works but when i push it to build release agents it fails since
its looking for the file in a different directory which is my release folder
but instead its looking for this file in what appears to be in a folder directory.
This is the directory its looking at E:\Agent_work\r10\a\xxxxxxxxx.testsettings,
here is my current way i have it set
<SettingsFile>xxxxxAutomation.testsettings</SettingsFile>
here is the error message
Error: The test settings file E:\Agent_work\r10\a\xxxxxxxxxx.testsettings, specified in the MSTestAdapter settings, is not available. Either access to the file is denied or the file does not exist. Ensure that the test settings file is available and try again.
instead of
E:\Agent_work\r10\a_XXXXX CI Build\drop\XXXXX_Automation_Test\bin\Release\xxxxxxxxx.testsettings
There is no documentation that states how to formulate the file path on msdn and didn't see
anything online.
I suggest you can add a Copy Files task to copy the missing file from .../bin/release folder(Use the browse option) to default working directory:
I suggest you resolve this issue via modifying your pipeline instead of settings file, so that you can also work well locally with the unchanged runsettings file.
In addition: Clean Target Folder input should be disabled(unchecked) cause our target folder is the default working folder. Deleting all files in that folder would cause unexpected issues.

SoapUI and absolute path

I managed to execute a bat file via Groovy in SoapUI with Runtime.runtime.exec("cmd /c C:\temp\test.bat") But I would like to have the bat file in a folder called scripts where my soapui-project file is.
Example:
Soapui-project file.xml
-- Scripts
--- test.bat
Runtime.runtime.exec("cmd /c Scripts/test.bat") doesn't work. I really need help here.
In a team, we share the project artifacts with different members and each may use different directory to copy them. So, in such situations absolute path in groovy scripts, like you mentioned, may not work if the directory gets changes.
To hand this, prefix of the path should be variable. And the rest of the path can fixed as the whole artifacts are still unchanged.
To handle that, use below which makes use of project directory as root and it gets that dynamically.
import com.eviware.soapui.support.GroovyUtils
def path = new GroovyUtils(context).projectPath
log.info "Project directory : ${path}"
Runtime.runtime.exec("cmd /c ${path}/Scripts/test.bat")

Project specific root path environment variable?

In a mixed languages project I have often to refer to configuration files, header files or even Makefiles. I usually use relative paths from the current file. It can be confusing in the case of a YAML configuration file parsed with an external Python script. Should I use the relative path from the configuration file or from the tool used to parse the configuration file? Also if I decide to move my files I have to adjust all the relative paths as well.
To solve this issue I am thinking to use relative paths to the project's absolute root path.
Is there any convention to define a project's path such as:
other_file: "$PROJECT_ROOT/src/foo/bar.xml"
One possible other solution is to always refer to Git, or define an environment variable for that:
other_file: "$(git rev-parse --show-toplevel)/src/foo/bar.xml"
$ export PROJECT_ROOT=`git rev-parse --show-toplevel`

Configure websocketd and PATH variable

I am trying to use this project (websocketd), but the third step is not working:
1-download the platform specific archive //done
2-extract files to folder of your choice or extract executable only // done
3-add the location of websocketd to your PATH variable
Currently i have this PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/www/cpu-stats/websocketd
But when i run this code:
websocketd --help
I will get:
bash: websocketd: command not found
websocketd location
/var/www/cpu-stats/websocketd
Any idea?
I think you should just add the folder "/var/www/cpu-stats" to your path without the executable file name.

Resources