Validate Boo script syntactically without running it - syntax

I have use BOO as an embedded script language in my own program. And I want to check the syntax errors of a script which a user writes. So I don't need to run the script by something like interpreter.Eval method and I need just running the first steps of compiler in order to discover the syntax error in user's script. Is there any way I can do that?
Thanks

http://boo.codehaus.org/How+To+Compile:
There are basically three ways to compile your boo code:
through the booc utility;
through the booc task (one of the nant tasks);
through the Boo.Lang.Compiler API;

Related

How to invoke modules of marklogic(xqy files) from shell script?

I want to write a shell script in which I can call a .xqy file and import some namespace also in that shell script.
You can use the REST API and some HTTP aware command line client like curl or wget.
There are many examples in the REST API's about how to do this, although it is fairly tedious to call .xqy code, pass it input , arguments and get output - possible.
You can use a program designed to do this such as xmlsh and the marklogic extension
http://www.xmlsh.org
Or you can write a 'simple' generic wrapper function in any of the languages which ML has a supported SDK, and then call that from the shell script.
You can make a 'custom' REST or HTTP endpoint which invokes the xqy and returns the results in the form you want.

How is it possible to have an user action in the "view" directory that trigger an ubus method?

I am trying to implement some code for a GUI using openwrt and luci.
I would like to know how to implement a button or a formulary that trigger a lua command when the user submit it.
I make a lua script using ubus to control gpios and relays and now I am trying to make a GUI in which users will be allowed to control each GPIO and relays through ubus commands.
I know the commands to call ubus methods through the GUI.
I did a new page with several graphic items. Is it possible to implement a button/formulary which changes a variable and this variable will be used by a lua script?
Thank you.
Yes, there's two simple methods that can achieve this:
POST/GET request to controller.
Using Lua functions in the HTM.
The first one should not be hard to understand conceptually and you can read about POST/GET requests in JavaScript (AJAX) here: https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
The second option is fine for something incredibly simple (or for testing purposes), but I would advise against using it over the first one just because there is less to type. All you need to do is simply surround your Lua code with <% (code goes here) %>.
However, there is another way which does not rely on Lua/JavaScript at all. You can make a config file (as it does seem you are saving something to it) and make an init script launch the service/change some parameters after any change to the configuration file using procd. Here's an example of how to do that: https://openwrt.org/docs/guide-developer/procd-init-scripts
Use curl commands, you can trigger a curl command when button is pressed and there by you can achieve your functionality

Open mail client from cli ruby script like a mailto link

I have written a ruby cli script which takes a CSV and generates a PDF report, based on said CSV. I'm fairly new to Ruby, so while it's probably not the greatest code, I'm pretty proud of what I've made.
At any rate, what I would really like to do now, is make my script email said PDF as an attachment. I'm sure there is a library that understands SMTP and can send this on my behalf, but I would like to modify the email body, and review the attachments before sending. So it seems like the simplest thing would be to have the script start a new email in my system default mail client, providing the recipient, subject, and boiler plate text, and attaching the generated file, kind of like a mailto: link in a web page (does mailto support attachments?).
Seems like there could be a system command that does this, completely unrelated to Ruby, which I could have my Ruby script call. That would be fine. If it's platform dependent, I'm on OSX, but I move around, so am interested in Windows and Linux solutions, too.
I guess plan B would be a way to jam a simple CLI editor into my Ruby script, to let me edit the email text, and then use an SMTP library to send the email. That seems harder, unless it's already been done.
Actually you can execute any ruby file from command-line interface (CLI) using console_runner gem. If you already have written code you can run it from command line. All you need is to add annotations (YARD-like syntax) to your Ruby code and then execute it from command line:
$ c_run /path/your_file.rb say_hello
/path/your_file.rb:
# #runnable
class MyClass
# #runnable
def say_hello
puts 'Hello!'
end
end

Ruby Test script structure advise

I am writing an automated test suit for a program that has mailing lists. I am trying to decide on the best practice for structuring the tools that I am going to use. The tests need to send email to a variety of email addresses then use the application to perform an action (approve, reject, discard). Then the script finally needs to check its mail and compare the email it has received against the list of emails it expects to receive. Here is the list of tools I am using.
Ruby,
Rake,
Selenium Webdriver,
Test-unit,
Jenkins
What I wanted to do was to treat everything as a dependency (in rake) of the last step(checking the email). My problem came when tried to make every email unique. I plan to embed the time the test was run at and a number assigned to each email in the test into the email (this number will be the same for each run of the test so I can identify where it should go). I need a way to pass the time stamp from the beginning of the test to the end of the test.
The solutions I see to my problems are to get rid of rake (because I can't or don't know how to pass a variable between tasks) or to write to a file then access the file in the seperate tasks.
Any recommendations?
I would advise setting an ENV variable in your Rakefile before each test is run, like this:
ENV['TIMESTAMP_CONTROL'] = Time.now.to_s
You can then reference the variable anywhere in your scripts and Rakefile until you reset it again like any other Ruby variable:
assert_equal ENV['TIMESTAMP_CONTROL'], #email_response_text

Can this be done? Bash script in a web application

I have a bash script (supports linux/unix), that installs an application.
Instead of executing the script in the terminal, I want to deploy it as a web application.
I want to make a web graphical interface for this script, so that the user can give the necessary inputs in the web forms and when ready,then pass these variables into the bash script to be executed.
This script obvious needs root privileges.
I plan to make it with with tomcat 7 / servlet / jsp. I want to deploy it as .war file.
First, can this be done? Is it possible?
Second, is there any example? I didn't find anything.
Third, any alternative method/better idea?
I'd try tomcat's own CGI support.
http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html
Well, it's possible, but keep in mind that sanitizing user input is hard.
What you want to do is use a scripting language or framework (I recommend sinatra), and use a html form to pass arguments to the backend. In the backend, you call your script by passing whatever arguments you want.
Example with sinatra:
post '/whatever' do
# This is dangerous!
`myscript #{params[...]}`
end
Err, but you want this to run on the client side, right?
So you don't really run it as bash on your system, you just template it within your web framework.
If the browser can then display this, it won't just d/l as a file, so you will need to set up a Content-Disposition: attachment header in the response to force a d/l.
You will naturally need the user's cooperation to run this as root on his or her system...

Resources