How can I change the file path of files referenced via the download role to not use a hashed folder? - python-sphinx

I want to provide a link to a file in my project, but I want this link to be human readable and perma-ish.
Doing this:
Link to file for reference :download:`myfile.json <../myproject/myfile.json>`.
Generates a link that looks like this:
...../myproject/docs/_build/html/_downloads/b4c73f3851c188db23a20daeed2c/myfile.json
Do I have control over this? I want the link to just be this:
...../myproject/docs/_build/html/_downloads/myfile.json
I would actually prefer the link be in the root so it's just:
...../myproject/myfile.json

The download role does what it says in the documentation, i.e., it creates links with a unique hash. I don't see a way around it unless the implementation is changed.
But
I would actually prefer the link be in the root
In this particular case we can (ab)use html_extra_path, adding this in conf.py
html_extra_path = ['../myproject/myfile.json']
and refer to the file with a regular hyperlink:
Link to file for reference `myfile.json <myfile.json>`_.
The file is then necessarily in the root folder (of the built HTML documentation), as that's what html_extra_path does. It cannot be put in a subfolder such as _downloads.

Related

Get absolute path to directory containing current FreeMarker

In Apache FreeMarker, how can I get the absolute path to the directory containing the current .ftl file?
For example, if I was processing the file /path/to/template.ftl, then I'm searching for a way to get /path/to inside of /path/to/template.ftl.
I've tried .current_template_name and friends, but these really only contain the name of the file, not its absolute path (from which I could get the parent directory). I've also tried absolute_template_name, but this just seems to prepend the name with a / to make the path seem absolute, but it does not resolve to the real absolute path.
Background: I'm templatizing Asciidoc files with with Freemarker, and the Asciidoc files must include other Asciidoc files which reside below the original directory of the .flt file, so they must not be searched relative to the temporarily "expanded" Asciidoc file.
The template paths that templates use are always virtual, and resolved by the TemplateLoader object set in the Configuration. TemplateLoader is just an interface, has multiple implementations, and so is a black box for FreeMarker. The actual location of the template can be inside a jar file, or even in the database table, so in general a template has no path on the file system.
Normally, you set up the TemplateLoader so that it can access all the templates you need. Then you don't need any tricks, and just use template paths.
Another possibility is to use a FileTemplateLoader that uses the root directory as base directory. This of course would be a bad idea for most applications (especially for web applications, for security reasons).

Fail to Download File Using Jmeter and relative path

I'm using JMeter to test concurrent downloads, and need to store it into specific folder.
I'm working on windows and using "Save response to a file". If I use the absolute path it all works exactly as I want it to work.
Now, I need to share this with a group (will be stored in repo) and want to change my obviously wrong absolute path to relative.
Now:
"~" - stores download in project root folder, where .JMX file is, but I want it in: "~/downloads/" so, in subfolder.
None of "regular" things work and yes I tried all possible combinations even those I know it should not work at all.
~/downloads/
./downloads/
~./downloads/
\downloads\
\downloads\
...
It or fails, and I can see in log error like:
~\downloads\1.x-gzip (The system cannot find the path specified)
Or It get's store in root with the filename "downloads" instead 1.x-gzip
Is there a way to do it, maybe using beanshell?
Most important, why is that behavior in JMeter so different, I mean if it works for "home" and "~/../" why it does not recognize subfolders?
Thanks
JMeter seems to be removing trailing slash so there is no way to bypass it apart from providing full path to the folder.
If you need to do it dynamically, relevant Beanshell script will look like:
${__BeanShell(import org.apache.jmeter.services.FileServer;FileServer.getFileServer().getBaseDir() + System.getProperty("file.separator") + "downloads" + System.getProperty("file.separator"),)}
You need to have "downloads" folder at the same level with your .jmx test script.
References:
__Beanshell() - function
FileServer class JavaDoc
How to Use BeanShell: JMeter's Favorite Built-in Component

How to create a variable in env.rb or hook.rb and call in cucumber feature ?

Thank you in advance for help.
I am trying to create variable in env.rb
File_path =("#{File.dirname(__FILE__)}/../../features/TestData/Testdata.html")
and call File_path in the Cucumber feature directly.
for example
...
And I upload a file from path "<File_path>"
...
Is the is a better way of doing this ?
Yes, there's a better way.
In your feature text, use meaningful names instead of file paths.
For example, any of these, depending on your goal:
And I upload a file of test data
And I upload my web page
And I upload some previously saved information
Then put the file path in your step file.
In general, feature descriptions should be plain language, not source code, file paths, env vars, etc

Dojo File Caching in Worklight

When using Dojo file caching with Worklight receiving a 404 Error when running in Simulator. It appears the file being loaded is not being copied from the common area to the device. Is there something else I need to define in my project to make that happen? There must be a convention and I wanted to follow it going forward as I expect to have more template files in the project.
My define statement in a .js file:
define(["dojo/_base/lang", "dijit/layout/ContentPane", "dojo/dom", "dojo/text!./templates/Order.html"], function(lang, ContentPane, dom, template){
...
var cp1 = new ContentPane({
title:"Order",
content: lang.replace(template, someJson)
}).placeAt("temp");
My folder structure:
In the common/js directory I have the above code in a .js file and I have a templates folder to keep the Order.html and I would expect to have other template files stored there in the future.
Error on the console:
GET http://localhost:10080/DojoProject/apps/services/preview/DojoApp/windowsphone8/1.0/default/layers/templates/Order.html 404 (Not Found)
It seems that the way you are specifying the path, browser tries to find the file in the "layers" folder which is sibling to "templates".
Have you tried to modify the "dojo/text!./templates/Order.html" to something like: "dojo/text!./../templates/Order.html" to navigate one level up, then go into the templates folder?
I'm not sure this will work, but I think it worths a try.

How to view drupal 7 sessions from an external PHP page?

I installed drupal 7 and I need to include a block of PHP code in the user profile page.
I created a new block and I put this code in it:
"include (http://mysite/sites/all/themes/campi_aggiuntivi.php)"
In "campi_aggiuntivi.php" I put the following code:
session_start ();
print_r ($ _SESSION);
But it returns an empty array.
How do I interact with drupal sessions in this external page?
Thank you very much for your answares.
Thank you all for your answers.
I'm trying to install a module and insert it into a block avege as I suggested.
I created the file test.info
name = Test Block
description = description Test Block
package = package Test Block
core = 7.x
dependencies[] = block
; Information added by drupal.org packaging script on 2013-02-01
version = "7.x-1.x-dev"
core = "7.x"
project = "Test Block"
datestamp = "1359680350"
But I can not figure out which function I put in the file test.module, to insert the test module management screen Blocks
Can you help me please?
Thank you again to all
I think you need to include Drupal Bootstrap and a few other necessary procedures. Here's a link to an issue on d.o that might help.
1st thing i want to suggest is don't include like this:
"include (http://mysite/sites/all/themes/campi_aggiuntivi.php)"
Use local path instead: "include (sites/all/themes/campi_aggiuntivi.php)"
But this depends on from where you are calling, if both the files are at same location(calling in user profile tpl file) then this might work: "include (campi_aggiuntivi.php)"
I presume you need session details to figure-out the user id, that information can be retrieved from $profile variable or arg(1)
I have not tested your code but the way you are trying to do is not the conventional way to extend Drupal functionality.
Also i hope print_r ($ _SESSION); is actually print_r ($_SESSION); in your code, i.e. without spaces.
If you want to add a block in user profile page, i recommend doing it the drupal way.
Drupal already has an excellent example for creating a block programmatically. Here is the link.
Have a look at block_example module inside it. It will give you relevant example codes that you can use to create the block.
The example also contains information about how to make the block appear in certain pages by default.
After you create the block place them in the region you would want to, like left sidebar, content etc of the relevant theme that is enabled on user profile pages.
Inside your custom module you would access to $_SESSION variable.
From here on you can include the code in campi_aggiuntivi.php inside your module itself.
Or use the following foolproof method to load the file. This would even work when you call it from a theme.
Say you want to use custom_module_name.campi_aggiuntivi.inc located in your custom module, from a theme then you can use module_load_include
For example,
module_load_include('inc', 'custom_module_name', 'custom_module_name.campi_aggiuntivi');
the above call would load custom_module_name.campi_aggiuntivi.inc from custom_module_name module folder. This way you don't have to hard code the path required to access the file.
Based on your update.. it sounds like you are now trying to create a block programmatically. There are example modules that you can download on Drupal.org. There is a block module in that download.

Resources