Call python script from Jira while creating an issue - python

Let say I'm creating an issue in Jira and write the summary and the description. Is it possible to call a python script after these are written that sets the value for another field, depending on the values of the summary and the description?
I know how to create an issue and change fields from a python script using the jira-python module. But I have not find a solution for using a python script while editing/creating the issue manually in Jira. Does anyone have an idea of how I manage that?

I solved the problem by using the Add-on Script runner in Jira. There I created a scripted field in Groovy and called the command prompt and run the python script from there. Here is a simple example of the script
def process = ['cmd', '/c', 'filepathToPython.exe', 'filepathToPythonFile.py'].execute()
process.waitfor()
return p.text
process?.err?.text can be used instead of process.text if one want to see eventual error messages.

Take a look at JIRA webhooks calling a small python based web server?

Related

Using prolog without the pl file

My python application works well and uses swi_prolog's consult, asserts, and query functions along with a pl file. However, when I call the code via web (I get access error at consult when trying to open the pl file).
So, I thought of using the prolog without the pl file consultation. I just want to embed the pl file content into prolog in a way so that I can use it in a similar way and I can continue with the query steps. Is there anyone who can guide me in doing this?
Thanks in advance,
Ferda
The SWI-Prolog manual has a chapter on deploying applications. In particular, it allows you to create so-called saved states of your program. This mechanism allows you to create a stand-alone package from your application, either from inside the application or from the command line.

How to modify all output files to conceal passwords in Robot Framework?

I'd like to conceal passwords from output files in Robot Framework.
In particular, I'm looking for a native possibility (not multiple commands):
to run a robot framework test retrieving one or more passwords from a vault through a custom keyword
and to remove in the output files (output.xml, log.html and report.html) all the strings equal to the password(s) retrieved.
I managed to do it for output.xml through --prerebotmodifier and a simple Python script I made, but the html files (log and report) are generated after the call to the Python script and so passwords are not concealed in there.
It's not possible to use --removekeywords since the password could be used somewhere else in the test and with DEBUG or TRACE it would be shown in the logs.
Another solution would be to run the Python script in a separate command (e.g. through ||) but this is not what I'd like to achieve.
robot --prerebotmodifier lib/password_clean.py -L TRACE testConceal.robot
Test to get password
${password}= get password ${SOME_PARAMETERS}
Log To Console ${password}
The expected result would be not to see the value of ${password} in output.xml, log.html and report.html with one Robot Framework native command.
You could use --removekeywords (https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#removing-keywords)
e.g.
--removekeywords get password
You could use NAME:
--removekeywords NAME:*password*. Any keywords with 'password' in title get removed.
I found a quick win which would be to use --listener instead of --prerebotmodifier. Still working on it, though.

How do I use a text file as input in Python?

This may seem like a simple question but this is the first time I have touched Python so bear with me.
I created a simple bash script to do some SMTP enumeration and have been trying to convert it into a Python script. The bash script was:
And so far the Python script I have is this:
But right now, I have to type in each username individually once and the script closes. I have created a simple text file with a bunch of possible usernames and want to be able to use all the usernames in that file instead of typing them in individually one by one but am not sure on how to do that.
with open('users.txt') as users:
for user in users:
s.send(...)

Launch XNAT pipelina via REST

I'm trying to write a script that would be able to launch the pipelines that are added to a specific project (i.e. the script would replace the user clicking on "build" for every subject on a specific project).
In my head I am dividing the problem into three tasks:
Getting the lists of subjects in PROJECT.
Getting the list of pipelines already added in PROJECT.
Launch the selected pipeline (which has to be present in the list generated in 2) for every subject (list collected in 1).
Now, as I see it, I'm already facing some problems:
How could I get a list of subjects for a PROJECT? Maybe using pyXNAT is easier...
How can I retrieve the list of pipelines added in a project?
How can I launch ONE pipeline on ONE subject (the same as clicking build on MR report page) via the REST-API? Is it possible?
I'm using XNAT 1.6.3
with Tomcat 6.0.41
and PostgreSQL 9.1
on Ubuntu 14.04
I hope my question is clear and thanks for your time!!
I have no answers regarding the pipelines, although I figure they can be triggered via REST protocol. For the basic stuff, have a look at the pyxnat documentation https://pythonhosted.org/pyxnat/index.html#short-examples

How do I create a web interface to a simple python script?

I am learning python. I have created some scripts that I use to parse various websites that I run daily (as their stats are updated), and look at the output in the Python interpreter. I would like to create a website to display the results. What I want to do is run my script when I go to the site, and display a sortable table of the results.
I have looked at Django and am part way through the tutorial, but it seems like an awful lot of overhead for what should be a simple problem. I know that I could just write a Python script to output simple HTML, but is that really the best way? I would like to be able to sort the table by various columns.
I have years of programming experience (C, Java, etc.), but have very little web development experience.
Thanks in advance.
Have you considered Flask? Like Tornado, it is both a "micro-framework" and a simple web server, so it has everything you need right out of the box. http://flask.pocoo.org/
This example (right off the homepage) pretty much sums up how simple the code can be:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
If you are creating non-interactive pages, you can easily setup any modern web server to execute your python script as a CGI. Instead of loading a static file, your web server will return the output of your python script.
This isn't very sophisticated, but if you are simply returning the output without needing browser submitted date, this is the easiest way (scaling under load is a different story).
You don't even need the "cgi" module from python, if you aren't receiving any data from the browser. Anything more complicated than this and you should use a web framework.
Examples and other methods
Simple Example: hardest part is webserver configuration
mod_python: Cut down on CGI overhead (otherwise, apache execs the python interpreter for each hit)
python module cgi: sending data to your python script from the browser.
Sorting
Javascript side sorting: I've used this javascript library to add sortable tables. This is the easiest way to add sorting without requiring additional work or another HTTP GET.
Instructions:
Download this file
Add to your HTML
Add class="sortable" to any table you'd like to make sortable
Click on the headers to sort
You might consider Tornado if Django is too much overhead. I've used both and agree that, if you have something simple/small to do and don't already know Django, it's going to exponentially increase your time to production. On the other hand, you can 'get' Tornado in a couple of hours and get something relatively simple done in a day or two with no prior experience with it. At least, that's been my experience with it.
Note that Tornado is still a tradeoff: you get a lot of simplicity in exchange for the huge cornucopia of features and shortcuts you get w/ Django.
PS - in addition to being a 'micro-framework', Tornado is also its own web server, so there's no mucking with wsgi/mod-cgi/fcgi.... just write your request handlers and run it. Be sure to see the demos included in the distribution.
Have you seen bottle framework? It is a micro framework and very simple.
If I correctly understood your requirements you might find Wooey very interesting.
Wooey is a A Django app that creates automatic web UIs for Python scripts:
http://wooey.readthedocs.org
Here you can check a demo:
https://wooey.herokuapp.com/
Django is a big webframework, meant to include loads of things becaus eyou often needs them, even though sometimes you don't.
Look at Pyramid, earlier known as BFG. It's much smaller.
http://pypi.python.org/pypi/pyramid/1.0a1
Other microframeworks to check out are here: http://wiki.python.org/moin/WebFrameworks
On the other hand, in this case it's probably also overkill. sounds like you can run the script once every ten minites, and write a static HTML file, and just use Apache.
If you are not willing to write your own tool, there is a pretty advanced tool for executing your scripts: http://rundeck.org/
It's pretty simple to start and can be configured for complex scenarios as well.
For the requirement of custom view (with sortable results), I believe you can implement a simple plugin for translating script output into html elements.
Also, for simple setups I could recommend my own tool: https://github.com/bugy/script-server. It doesn't have tons of features, but very easy for end-users and supports interactive execution.
If you don't need any input from the browser, this sounds like an almost-static webpage that just happens to change once a day. You'll only need some way to get html out of your script, in a place where your webserver can access it.)
So you'd use some form of templating; if you'll need some structure above the single page, there's static site / blog generators that you can feed your output in, say, Markdown format, and call their make html or the like.
You can use DicksonUI https://dicksonui.gitbook.io
DicksonUI is better
Or Remi gui(search in google)
DicksonUI is better.
I am the author of DicksonUI

Categories

Resources