I want to store all my resources file/scripts/payload in one package & through call function, I want to read that file or scripts. To use classpath in this scenario is creating a problem.
In karate config, I'm setting a variable as application_path with an absolute path which I'm referring in a feature file
Karate config
{
application_path:"/home/local/IdeaProjects/project/src/test/java/module"
}
can anyone please help how to set or use an absolute path
This is of course not at all recommended, but we support the file: prefix for absolute paths.
Please refer to the docs: https://github.com/intuit/karate#reading-files
* def payload = read('file:/home/foo/bar.json')
Related
I need to display a yaml file as an array but i but I can't display it.
I have create a service, and my controller call this service.
In my service i try to call my yaml like this :
$value = Yaml::parseFile('public\assets\organizations.yaml');
return $value;
But that return me that error :
File "public\assets\organizations.yaml" does not exist.
You are specifying the file with a relative path. This will not be resolved relative to the file it is in but relative to the current working directory you are in when executing the script. Since this depends on various factors it will always be troublesome.
Thus you should always use absolute paths. In symfony you can get the base path of your project via the kernel.project_dir configuration parameter.
Your code does not provide enough context to understand how or where you are using it. But if it is inside a controller extending AbstractController you can use getParameter():
$projectDir = $this->getParameter('kernel.project_dir');
$absolutePath = $projectDir . '/public/assets/organizations.yml';
$value = Yaml::parseFile($absolutePath);
return $value;
Also note that using \ as the directory separator won't work under Linux/Unix-like systems where / is used as directory separator!
Since / will work as directory separator under Windows, too, it is easiest to use it for cross-OS compatibility. Alternatively use the DIRECTORY_SEPARATOR constant.
I've created an installer package based on the Qt installer framework with multiple components.
I needed to install each component in the appropriate directory.
Is it possible to specify the target directory for the individual component? I am referring to something like this:
var appData = installer.environmentVariable("AppData");
if (appData != "")
component.setValue("TargetDir", appData+ "/MyComponent");
Thank you in advance.
This question has already been answered, but I thought I would add a more detailed answer.
The documentation states that "for each component, you can specify one script that prepares the operations to be performed by the installer."
The Qt installer framework QtIFW comes with a set of examples, one of which is called modifyextract. Using this, I modified my package.xml file to include the line
<Script>installscript.qs</Script>
I then added a file installscript.qs to my package meta directory with the following content
function Component()
{
}
Component.prototype.createOperationsForArchive = function(archive)
{
// don't use the default operation
// component.createOperationsForArchive(archive);
// add an extract operation with a modified path
component.addOperation("Extract", archive, "#TargetDir#/SubDirectoryName");
}
The files in the package data folder were then installed in the subfolder SubDirectoryName
You need this based on the documentation:
Extract "Extract" archive target directory Extracts archive to target directory.
In my case, the component.addOperation("Extract", ... line resulted in extracting to #TargetDir#.
Instead, use one of the 'Operations> options in the Package.xml file.
I want to get the parent directory path of my solution's startup project, by testing that code
string parent = System.IO.Directory.GetParent(Server.MapPath("~/"));
I get the directory where my solution's startup project is currently placed. Why ?
I am not sure why this happens, at the momemt. But you can do
string parent = new DirectoryInfo(Server.MapPath("~/")).Parent.FullName;
to get the parent directory path.
I try to find a answer why System.IO.Directory.GetParent(Server.MapPath("~/")) does not work and update this if i found something.
Update
I found a possible answer on another Stackoverflow question who GSerg say
I can only assume Directory.GetParent(...) can't assume that C:\parent\child is a directory instead of a file with no file extension. DirectoryInfo can, because you're constructing the object that way.
The reason this is happening is because Server.MapPath is appending a \ at the end of the path (even if you remove it from your MapPath), for example:
C:\foo\bar\
If you try to get the parent directory of that, it will give C:\foo\bar without the slash.
So this will work:
var path = System.IO.Directory.GetParent(Server.MapPath("~").TrimEnd('\\'));
Here is an alternative:
var path = new System.IO.DirectoryInfo(Server.MapPath("~")).Parent.FullName;
Looking for a build-time CSS combiner/minifier that respects relative URL references.
That is, if one of the files I am combining is at
/path/to/style.css
and contains
background-image: url(images/my-image.png)
the resulting file should contain
background-image: url(/path/to/images/my-image.png).
Should work cross-platform Mac and PC, so either .NET via Mono or Node seem like obvious choices.
Check out WebAssets / Github
Asset management application for Python web development - use it to
merge and compress your JavaScript and CSS files.
It includes filters/ precompiles for cssmin, cssutils, yui_css, less, sass, clevercss, compass, scss, coffeescript, gzip, etc.
Specific to your question:
cssrewrite Source filter that rewrites relative urls in CSS files.
CSS allows you to specify urls relative to the location of the CSS
file. However, you may want to store your compressed assets in a
different place than source files, or merge source files from
different locations. This would then break these relative CSS
references, since the base URL changed.
This filter transparently rewrites CSS url() instructions in the
source files to make them relative to the location of the output path.
It works as a source filter, i.e. it is applied individually to each
source file before they are merged.
No configuration is necessary.
The filter also supports a manual mode:
get_filter('cssrewrite', replace={'old_directory', '/custom/path/'})
This will rewrite all urls that point to files within old_directory to use /custom/path as a prefix instead.
General Usage:
from webassets import Environment
my_env = Environment('../static/media', '/media')
""""As you can see, the environment requires two arguments,
the path in which your media files are located, as well as
the url prefix under which the media directory is available.
This prefix will be used when generating output urls. Next,
you need to define your assets, in the form of so called
bundles, and register them with the environment. The easiest
way to do it is directly in code:""""
from webassets import Bundle
js = Bundle('common/jquery.js', 'site/base.js', 'site/widgets.js', filters='jsmin', output='gen/packed.js')
my_env.register('js_all', js)
In this case you'll replace your js src with output.
Here is an alternate notation:
directory: ../static
url: /media
debug: True
updater: timestamp
bundles:
bundle-name:
filters: sass,cssutils
output: cache/default.css
contents:
- css/jquery.ui.calendar.css
- css/jquery.ui.slider.css
Also has special hooks for Django, Flask, Jinja2, Werkzeug..
Documentation is here. Hope this helps!
Here's a basic Python script that will combine all CSS files in a directory and replace references to your images folder:
import os
import fnmatch
output_text = ''
for filename in os.listdir('.'):
if fnmatch.fnmatch(filename, '*.css'):
output_text += open(filename, 'r').read()
output_text = output_text.replace('url(images', 'url(/path/to/images'))
f = open('combined.css', 'w')
f.write(output_text)
f.close()
This is off the top of my head and hasn't been tested, so it might contain errors.
In response to your comment:
Alternatively, you could use server-side CSS, like SASS/Compass or LESS.
With SASS/Compass you can dynamically change the path to assets (images) using the config.rb file, or from the command-line. You can toggle between relative and absolute paths easily in the same way. Your stylesheets are automatically compressed. To make sure that your files are combined, you can just create a master.scss file and #import each file. Most of my experience is with SASS but I believe LESS has similar features.
This is probably not ideal, however. It would be much simpler, portable, and more efficient to take care of this in a Python/Ruby script. It wouldn't take much effort to expand on the Python script above to make it compress the output file and match all relative paths. Then you can make it automatically run by having something like Foreman watching the build directory for changes.
How may I know File.nativepath from the folder that my .app or .exe AIR app is running?
When I try this I just get
'/Users/MYNAME/Desktop/MYAPP/Contents/Resources/FILETHATINEED.xml'
I need put this on any folder and read a xml file in the same folder. I don't need my xml file inside the package.
I need this structure
/folder/AIRAPP.exe
/folder/FILE.xml
Thanx in advance.
From what I can find there is no way to get that without doing some work yourself. If we assume that the File.applicationDirectory points to the wrong place only on Mac (which seems like the case), we can do this:
var appDir = File.applicationDirectory
if ( appDir.resolvePath("../../Contents/MacOS").exists ) {
appDir = appDir.resolvePath("../../..");
}
That is, check if the parent directories of the app directory match the Mac .app bundle directory structure, and in that case use the parent's parent's parent (which should then be the directory containing the .app bundle).
I believe you want to use File.applicationDirectory.