I am writing a Django management command. The command itself is located under myapp/management/commands/mycommand.py. I need to write an additional class which I would like to place in an extra file.
Should this file live in
myapp/extrafile.py or
myapp/management/commands/extrafile.py
What would be a recommended location. The class is only need for the management command, not elsewhere in the app.
You can create an additional file in myapp/management/commands/ that starts with underscore. It is not going to be detected as a management command (check this).
So, your command in: myapp/management/commands/mycommand.py
And your helper in: myapp/management/commands/_myhelper.py
Generally in these cases you are writing a helper file for that file so You can create a helper folder like this:
myapp
-helpers
--commands
--other_helpers
you can read more about helpers here, they can be separated from the original class/function.
Related
I am attempting to build a file in Puppet 5 using an ERB template. This ERB file uses class variables in the normal fashion, but is also constructed by inserting another Puppet-managed local file. However, I find that whenever I update the inserted file, it takes two Puppet runs to update the ERB-generated file. I want the updating to happen in one Puppet run.
It is easiest to see this with an example:
# test/manifests/init.pp
class test {
# This file will be inserted inside the next file:
file { '/tmp/partial.txt':
source => 'puppet:///modules/test/partial.txt',
before => File['/tmp/layers.txt'],
}
$inserted_file = file('/tmp/partial.txt')
# This file uses a template and has the above file inserted into it.
file { '/tmp/layers.txt':
content => template('test/layers.txt.erb')
}
}
Here is the template file:
# test/templates/layers.txt.erb
This is a file
<%= #inserted_file %>
If I make a change to the file test/files/partial.txt it takes two Puppet runs for the change to propagate to /tmp/layers.txt. For operational reasons it is important that the update happen in only one Puppet run.
I have tried using various dependencies (before, require, etc.) and even Puppet stages, but everything I tried still requires two Puppet runs.
While it is possible to achieve the same result using an exec resource with sed (or something similar), I would rather use a "pure" Puppet approach. Is this possible?
I am attempting to build a file in Puppet 5 using an ERB template. This ERB file uses class variables in the normal fashion, but is also constructed by inserting another Puppet-managed local file.
A Puppet run proceeds in three main phases:
Fact collection
Catalog building
Catalog application
Puppet manifests are completely evaluated during the catalog building phase, including evaluating all templates and function calls. Moreover, with a master / agent setup, catalog building happens on the master, so that's "the local system" during that phase. All target system modifications happen in the catalog application phase.
Thus your
$inserted_file = file('/tmp/partial.txt')
runs during catalog building, before File[/tmp/partial.txt] is applied. Since you give an absolute path to the file() function, it attempts to use the version already present on the catalog-building system, which is not necessarily even the machine for which the manifest is being built.
It's unclear to me why you want to install and manage the partial result in addition to the full templated file, but if indeed you do, then it seems to me that the best way to do so would be to feed both from the same source instead of trying to feed one from the other. To do this, you can make use of the file function's ability to load data from a file in the (any) module's files/ directory, similar to how File.source can do.
For example,
# test/manifests/init.pp
class test {
# Reads the contents of a module file:
$inserted_file = file('test/tmp/partial.txt')
file { '/tmp/partial.txt':
content => $inserted_file,
# resource relationship not necessary
}
file { '/tmp/layers.txt':
# interpolates $inserted_file:
content => template('test/layers.txt.erb')
}
}
Note also that the comments in your example manifest are misleading. Neither the file resource you present nor the contents of the file it manages are interpolated into your template, unless incidentally. What is interpolated is the value of the $inserted_file variable of the class that evaluates the template.
We want to create a HelperUtility.cfc with common methods for our tests to use. If we put the file in /tests/lib/HelperUtility.cfc, can we tell TestBox, don't try running any tests in /tests/lib? If not, can we add something to the component tag to skip the entire file, rather than adding skip to all the methods in the component individually?
There's no way to do that unfortunately.
I have tried to skip some manual mocks that were created inside a tests/mock folder, but you cannot configure TestBox at runtime to skip a specific folder if you decide to run the tests for a parent folder.
The only work around that worked for me was to create a specs subfolder in the parent tests and then call the testbox runner with a directory argument of the specs...
For example: http://localhost:8500/testbox/system/runners/HTMLRunner.cfm?directory=tests.specs
I am interested in creating a config.cfc which I want to use in differenct components.
in PHP one can create a config.php file which simply return an array. and in other php files this can be included like
use config.php
Can I simple include a .cfm file in any .cfc component? of a config.cfc which simply returns a STRUCT?
I'm not sure how to answer your question because I don't fully understand what you're trying to accomplish. In one sentence you need to return an array and in another sentence you need to return a struct. If you're looking to create a config.cfc your method(s) can return either datatype (array or struct).
To answer your other question, yes you can include a .cfm file within a .cfc. I've done it in the past, although it's not best practice.
What I would suggest instead, in your config.cfc, create any needed methods then use CreateObject() in your calling .cfm or .cfc for usage.
I have seen several projects that use a .cfm file as a config file and it sets a Coldfusion struct variable with setting values. Using cfinclude will then load the file and set a config variable (usually a struct). It could just as easily set an array although I think structs would be more flexible. There is usually logic in the code to cfinclude the config.cfm file once and store the setting in the application scope.
Another option is to use a .json file that contains the same kind of thing but in JSON format. Here's an example of an open source project that does that:
https://github.com/tonyjunkes/CFFormProtect-Revamp/blob/master/cfformprotect/config.json
The controlling code reads the file and uses deserializeJSON() to convert it to a ColdFusion struct. Since it is open source you could download this project and see exactly how it is working.
Yes, you can cfinclude a .cfm from a .cfc file.
I have a suite which has 50 test cases. When I execute my suite, I get all the failed screenshots listed in the project's folder. I want to point and store those screenshots to a different directory with the name of the test case. I wanted it to be a one time setup than doing it explicitly for every test cases.
There's quite a few ways to change the screenshots default directory.
One way is to set the screenshot_root_directory argument when importing Selenium2Library. See the importing section of Selenium2Library's documentation, and importing libraries in the user guide.
Another way is to use the Set Screenshot Directory keyword, which will do pretty much the same thing as specifying a path when importing the library. Though, using this keyword you can set the path to a new one whenever you like. For example, you could make it so that each test case could have it's own screenshot directory using this keyword. According to your question, this may be the best solution.
And finally, you may also post-process screenshots using an external tool, or even a listener, that would move all screenshots to another directory. Previously mentioned solutions are in most cases much better, but you still may want to do this in some cases, where say, the directory where you want screenshots to be saved would be created only after the tests have finished executing.
I suggest you to do the follow:
For new directory, you should put the following immediately after where you open a browser such:
Open Browser ${URL} chrome
Set screenshot directory ${OUTPUT FILE}${/}..${/}${TEST_NAME}${/}
For replace the screenshot name from the default to your own name, create the following keyword:
sc
Capture page screenshot filename=${SUITE_NAME}-{index}.png
Then, create another keyword and run it on Setup's test case:
Register Keyword To Run On Failure sc
In the above example, I created a new folder with the test case name, which create a screenshot (in case of failure) with the name of suite project name (instead of 'selenium-screenshot-1.png').
I need to provide non-techie user ability to reliable download a few large files (3Gb) from URL without revealing the source URL of the file. Ideally I need single exe (without dependencies) that will download file from URL, specified inside exe: when user click on exe it just need show prompt where to save the file, and(optionally) will provide the user with some progress bar, for instance. The target URL can be specified directly in
the resource section, so I can edit URL path with HEX editor when I need set another path.
Wget are not suitable in my case, as its command line utility and requires user to specify an URL.
You could use the URLDownloadToFile function. Implement the IBindStatusCallback interface to receive progress information.
You really can't hide the source URL. Why are you trying to do that? If an end user runs tcpdump while they are running your program, they'll see where packets are coming from and going to.
I'd just provide them with a small batch file which calls ftp.exe. Tell your end user to drop the .BAT file where the downloaded file should go, and click it.
That solves quite a few problems, e.g. you know that your end user will be able to find the directory.