RPM Post Install Execute with Python - python

I'm working on a deployment process for work and have run into a bit of a snag. Its more of a quality of life thing than anything else. I've been following Hynek Schlawack's excellent guide and have gotten pretty far. The long and short of what I'm trying to do is install a python application along with a deployment of the python version I'm currently using. I'm using fpm to build an RPM that will then be sent and installed to site.
As part of my deployment, I'd like to run some post-install scripts. Which I can specify in fpm using the "--post-install {SCRIPT_NAME}" This works all well and good when the script is an actual linux script. However, I'd really like to run a python script as my post-install. I can specify an executable python script, but it fails because I believe it is trying to execute the script as: bash my_python_script.py
Does anyone know if there is a way to execute a python script post-install of an RPM?
Thanks in advance!

In the spec file you can specify what interpreter the %post script is for by using the -p parameter, e.g. %post -p /usr/bin/perl .

Related

running a python script through powershell

this may seem basic, but could somebody run me through how to run a python file (one that's already created), through powershell? I know absolutely nothing about powershell despite hours of looking online to learn
Thanks all
It is happily very similar, if not the same, as running a python script from the normal command line.
First you're going to need to have python installed and in your path.
To test this try python --version in powershell. You should get output like: python 2.7.
If that worked fine then you run your script by typing python followed by the script name i.e. python test.py (if its in another directory you will need to go to that dir or add the dir to the filename).
If that didn't work you probably need to install python: https://www.python.org/
Provide the path where you have installed the Python, followed by the path of the Python script:
'path of python.exe' 'Path of the python script'
Example:
C:\\Python27\python.exe 'D:\\Project\script.py'

Questions about compiling Python in debug mode

I am using Ubuntu 12.04, Python 2.7.3.
I am having a segmentation fault in a C extension I have co-written. It seems to come from a pointer that was not free'd properly.
I then use valgrind to find memory leaks. According to that answer, I have to compile Python in debug mode to get a valgrind friendly version of Python and get rid of its irrelevant reports.
How to compile Python in debug mode?
Even though the answer I linked answers part of that question, it does not provide me enough details.
Indeed, I want to understand what is happening, not just type things at some places because "who knows? It could work".
Hence, I would like to know:
What to download to compile Python?
Where to type that ./configure?
What is going to happen to my current installation? Is it going to affect my system?
I have read at many places that many processes on Ubuntu 12.04 are
managed by Python and I do not want to mess up anything.
I am also trying to find answers to the questions mentioned by Yair Daon's comment:
Do you have to recompile Python once you are done using its debug
compilation?
If yes, how to compile Python back to its standard mode?
Here are some inputs for anyone trying to compile Python in debug mode on Ubuntu:
Download the version you need from the python website.
Untar it using tar -xf and go to the new directory.
Example:
tar -xf Python2.7.3.tgz
cd Python-2.7.3
Configure your python installer for debug mode, using ./configure --with-pydebug. It will create a Makefile that you will just have to run.
Compile the sources to create your new python interpreter by running the Makefile, using: make install.
As you create a new interpreter, your system's Python will stay clean.
If you compiled it using --prefix=/home/username/workspace/project/python/, you can now run your script with your new Python interpreter using:
/home/username/workspace/project/python/bin/python script.py
Or, you can also add the shebang line #!/home/username/workspace/project/python/bin/python at the beginning of your script, give it the execute privilege (sudo chmod 764 script.py) and run it more easily using your new Python interpreter by typing ./script.py.
Note: you may want to check Python's documentation for more configuring / compiling flags
(such as --prefix / -j, thanks Chris for the link).

SVN Python API with TortoiseSVN

To use the SVN API with a Python script is it enough to have TortoiseSVN installed or do I need another SVN client?
I am using the cmd line features of tortoiseSVN but I'm looking for more advanced possibilities to work with SVN and wonder if I need to install another SVN client or so..
Thanks, Martin
Unless you're going to shell out to run a command-line program from within Python, you should be using PySvn or the "Subversion for Windows" distribution which includes Python libraries.
If you still want to run a command-line program from your Python script, use either the svn.exe that comes with the TortoiseSVN installation, or the one from the above-referenced Subversion for Windows. The TortoiseSVN command-line program (TortoiseProc.exe) is not intended to be used from within other scripts/programs like you describe.

/init.d/function + python version

I am trying to daemonize celery and celerybeat. I have downloaded the celeryd and celeybeat files from github and placed them in /etc/init.d/ (celery and celerybeat) with the corresponding config files under /etc/default/.
My problem is that when I run these two files, celeryd and celerybeat use system python (2.4), and as a result cannot find other installed applications under python 2.7. Python 2.7 is in ~/.bashrc and /.bash_profile files, so I do not have any problems running other applications, except when workers fail to work. When I run python ...../manage.py celery ( with all options) everything works like a charm.
Please let me know how I can force /init.d/function to run python2.7.
I have tried to implement #! /bin/sh python, but it does not work.
scripts in /etc/init.d are usually run as root on system startup. root's ~/.bashrc (that is /root/.bashrc) will look totally different from yours (e.g. /home/reza/.bashrc).
your shell will behave slightly differently if you are running it interactively or not.
hence there is no use in trying to run the python interpreter through /bin/sh, it only adds overhead.
what you want is to add a proper shebang that tells the system which interpreter to use for your script.
e.g.
#!/usr/bin/python2.7
will use the python2.7 binary installed in /usr/bin.
(so whenever you run /etc/init.d/foo.py the system really runs /usr/bin/python2.7 /etc/init.d/foo.py)

How to run python files without using terminal or gui?

Hello gyus i have started python and i want to know how can i excecute python file without using terminal.Just like the most games using (exe) file extension but for py files.I have tried py2exe but it doesn't show anything on the screen. I tried to make excecutable the py file with no luck. Please tell me how to excecute the and if there is an option whithout using a specific program for that.
My system is : Windows 7 / Ubuntu 12.04
Here, have a look in my blog, It explains how ca you do it in Ubuntu.
http://insidepython.wordpress.com/2012/08/04/hello-world-or-how-or-say-ni/
but basically:
Add this line to the beginning of your script
#!<location of your python interpreter>
To find out where your python interpreter is installed:
$ sudo find / -name "python"
After executing the previous, you should get the location of your python interpreter, then you need to set the environment variable, in my case python executable is located in /usr/bin/python
$ export PATH="$PATH:/usr/bin/python"
Then you need to set the file attributes to executable, you can look more into file attributes in Unix/Linux here http://en.wikipedia.org/wiki/Chmod
$ chmod +x shrubbery.py
And finally to execute your application
$ ./shrubbery.py
For Windows, there's also a python script called GUI2Exe that I have used in the past to create distributable versions of python scripts as apps. It's available at
http://code.google.com/p/gui2exe/ and is, in my opinion, very simple to use. Tutorials and whatnot are easy to find on Google.
It uses py2exe (or any other Python compiler library) to put together the script, but it doesn't require any syntactically annoying setup.py file.

Categories

Resources