I have a .pm file with a 30+ subs. The functionality in those subs needs to be called from my CakePHP pages. What is the Cake way to include the .pm file in a CakePHP project so I can call the subs from a View or Controller?
Where should I put the .pm file? How should I include the file into the CakePHP project? How do I call the subs in the .pm file?
I can't find anything in the CakePHP documentation. The place that it seems it should be is in the App, but I can't find anything to do what I want to do.
CakePHP is a PHP framework. According to Wikipedia, a .pm file contains Perl source code basically composed of function definitions. From the PHP point of view, that's as reusable as the blueprints of a Toyota. I suppose it's technically possible to write a PHP extension that's able to compile the Perl code and expose its methods to PHP functions but it'd be a daunting task.
The obvious workaround is to write a Perl executable that loads the module, does whatever you need and prints the output in a format that PHP can use. Afterwards, program execution functions are your friends.
Depending on how your perl scripts work(I have no idea what the difference between .pm and .pl is ), you could create a model or component and access the data using PHP's exec function like so:
exec("path_to_perl /path/to/script.pl arguments to be passed",$output);
Wrap the perl output in your model/components methods. Than in your controller just call the model/component method passing in the relevant arguments.
NOTE: just make sure when running this command you have properly secured the input/output data from the scripts
Related
My question should be very simple to answer for anyone not being a self-taught newbie like me...
On this page is a cheatsheet concerning a function to be used in GIS/DB environnement : http://www.bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg
I would like to create a script allowing users to just have to click on it to launch the process, given the proper datas. But I don't understand how to use this. It obviously doesn't work in a Python console, nor directly in the windows console. How is it supposed to work ? What language is this ?
Thanks
shp2pgsql is indeed a command line tool. It comes with your PostgreSQL/PostGIS installation (usually) and, if not accessible via PATH-variable, can (usually) be run from within the /bin-folder in your PostgreSQL-Installation. You can also always 'make' the programm from source in any location yourself, if needed.
EDIT:
One way to set up a script (independent of whether you use it within qgis own python environment or not) would be to use Pythons subprocess (or os.system) module (check related question here) to write to shell and execute shp2pgsql.
A slightly more sophisitcated solution to (batch) insert (multiple) shapefiles via script could be to implement ogr2ogr via gdal/ogr module within python (check this blog). That, however, would require a working installation of the gdal core library, and the respective Python bindings (at least to use outside of QGIS Python environment, where it is pre-installed AFAIK), which can be tiresome at times. Once installed correctly, it offers a powerful (I dare say almighty) toolset for geodata management and manipulation via Python, though.
Apart from that, the blog link I provided also states the implementation of a batch insert script/tool (which operates ogr2ogr) in qgis 2.8 toolbox...maybe that can help you, either with your work directly or (via sourcecode) to point you in the direction of creating your own tool.
I am playing with CefGlue (the .net wrapper around chromium embedded") I need to make some proof of concept so I create my own special html files that contains what I need to test. However I can't find a way to load those files.
The CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, url); requires an url and there is no overloaded method that accepts the content as string. So the question is: How to load html file from disk?
I've not used CefGlue - but in general you can use a custom cef resource handler to load the file. Briefly, when CEF sees your URL, they will call through a resource override handler you set up, which will then read that resource into a byte stream. In our case we read an html file compiled into our application resources. In your case I suppose you could also read the resource from disk at that time, though I've not done this. If you can compile resources into your C# app, you can add the html file into the Resources if you prefer.
We pass the url to CreateBrowserSync() in our case, and CEF ends up calling our ResourceHandler to load it. The CefClient c++ sample has an excellent example of this, see resource_util_win.cpp.
This is set up in a Handler override in CefResourceHandler. We overrode GetResourceHandler, their example overrides ProcessRequest in SchemeHandler. See scheme_test.cpp in the CefClient sample.
Most of the code from their samples is pretty boiler plate and you should be able to use what they have as the basis for your implementation - it's really too much code to list it all out here though.
I found a solution: just pass the full path to the file in the url parameter and everything works fine. It's just like chrome opening file from disk so I don't know why I did not tried that the first time.
I'm trying to get some automator script going but I have no clue how to achieve it. It's like this:
in Processing I exported a batch of 1850 SVG's. These SVG's now have to be opened in an application called Cenon. This application can save SVG's as .hpgl files.
It's no problem to open a file in a specific application like Cenon when it's added to a folder. That works fine.
But how do I save this file in a specific extension like .hpgl and create a variable name? Because Cenon always opens a file with the name 'UNTITLED'.
So I need to do:
automatically open file one by one in Cenon
save file as .hpgl file
save file with variable name like (0001, 0002, 0003, 0004, 0005, etc.)
I hope someone can help me!!
Thanks in advance,
Fons.
First of all, let me make a distinction between two related technologies:
AppleEvents which are messages that can be used for different applications to communicate with each other, asking each other to do tasks.
AppleScript which is one kind of scripting language that can send and receive AppleEvents to and from Mac applications.
You can't use AppleEvents with Cenon but you still may be able to use AppleScript with Cenon. I know that you can't use AppleEvents with Cenon because I downloaded Cenon version 4.0.1 from the web and I tried to open up it's AppleEvent dictionary with the "AppleScript Editor.app" application that comes with OS X.
So, AppleEvents are out. This means the "tell" command in AppleScript can't tell the Cenon.app to do anything with AppleEvents, but you may still be able to use AppleScript.
AppleScript can be used by simulating user menu-selections and key strokes instead of using AppleEvents. Using AppleEvents would be better, but sometimes, using AppleScript, you have to go through the user interface.
An alternative to resorting to using AppleScript to simulate the user-interface (UI) would be to use a shell-command. It just seems to me that this would be a better solution, but you would have to find a Unix shell command that was compiled for Mac that would convert from .svg to .hpgl
If you really want to use AppleScript and Cenon.app, here is a link to study about using AppleScript going through the UI of an app:
http://www.macosxautomation.com/applescript/uiscripting/
AppleScript was originally designed to be a scripting language to take some of the functionality with application A, and then take some of the functionality of application B, etc, and glue it together with a little logic from AppleScript and empower the user to more easily automate their tasks.
AppleScript was designed to be an alternate user-interface, going through AppleEvents, but AppleEvents are not as widely supported as they could be by applications, so this kludgy solution of having AppleScript go through the GUI is commonly done.
Again, I think that a shell script would be a better solution for this problem and you could call is "solution.command" or you could embed the shell script into an Automator Workflow saved as an Application or embed the shell script within an AppleScript saved as an application. Either one work work.
We have an existing C library (DLL / .so) that processes some data. There's a call to initialise it, then a call to give it the parameters it needs to process, and then a few calls to retrieve the different output parameters you are interested in. The initialise is then called to reset the library for the next session. We have an app built around this to easily input the data and view the results.
Now we want to take this library and make it available as a web service. We are looking for the simplest (read quickest) way to do this. As I see it, we need:
A web services framework (Apache Axis2/C looks good for existing C code)
Some way to start a process for each incoming query (not sure if Axis2 can do something like this).
So my question is : Is Axis2/C the simplest way, or is there another simple solution?
If you have an external executable you can call, how about using something like Apache with FastCGI?
I am working with a MATLAB project, and would like to be able to configure variables and paths without re-creating the executable (currently done by using MATLAB's built-in deploytool). I realize I can create a simple text file, listing key=value pairs, and read that in during run-time. There doesn't seem to be any built-in support in MATLAB for creating configuration files that follow a standard format.
Are there any standard existing ways to use configuration files for MATLAB-generated executables?
1) Add your resource to the package in DeployTool in the shared resources part
2) Read by using:
fullfile(ctfroot(),'config.txt');
Edit : That is suitable if your configuration is "private", that is the user should not edit it. In this case it is deployed together with your program as a resource. If you want a "public" config for the users, I know of no better way than to do what you offered.