Which Toolkit to develop Mac OSX/Windows Daemon service - python

I need to develop a daemon service which also has presence in System Tray. The system tray icon allows users to customize/access some options through right click menu. It might open a window as well manage those options in a better way.
The app would mostly be communicating with a RESTful service, posting and downloading files.
Now I know that for any daemon service, it needs to be native. However we don't have the luxury to maintain 3 different dev pipelines, specially since the app is experimental(but might land up in hands of users)
I have experience in Java/Scala, followed by C++/Python/JS. I would prefer java/Scala (existing codebase) but open to frameworks in other languages.
I was thinking of doing a scala based app with swing for windowing, but it is not pretty.
Any ideas?

We have an App, same base code, running on Windows, OSX and Linux (with system tray) using these two set of components:
The Tanuki Java Service Wrapper to handle the lifecycle of the app. It also allows installing the component as a "native" windows service. Version 3.2.3 is under LGPL if that helps.
The Java 6 java.awt.SystemTray which is supported on most platforms. On OSX, we use a modified version of macify to implement OSX specific gimmicks like doc icons

You could go with JavaFX and the ScalaFX bindings. They look to be very actively maintained, and the syntax seems pretty clean. Only trouble is that it seems to have poor support for using the system tray - see this discussion for details and some workarounds.

You can use Real Studio to create a Windows Service and OS X/Linux daemons. Real Studio creates native apps for Windows, OS X and Linux.

Related

Python Windows Service to Daemon Service

I have written multiple python windows services, and now I need to port them to Linux.
These services are constantly repeating until an endflag is raised signalling the stoppage of work. This is just like any service in windows, it implements the start/stop/restart methods using the pywin32 libraries to hook into the windows' framework. Is there a framework for these command in Linux? I cannot find any documentation on this.
is there a pattern to follow when developing Linux services (daemons)? If so, where can I find these resources?
I know there are many 3rd party packages for Linux Daemon on pypi, does anyone have preferences?
Is there a way to see if a service is running on a different Linux box? Can you start and stop a service on a linux box remotely?
If you cannot check if a service is running in linux, what I was thinking of doing was creating a server that accepts a variety of commands like:
STATUS - informs if a job is running on machine X
TURNOFF - ends the service (if it can be done)
TURNON - turns the service on a machine (if it can be done)
Sorry for the broad range of questions, but I'm a Linux noob.
Thanks
You have a number of different options, but in general you're going to need to look into the Linux side of things, outside of Python, to decide what makes sense. What Linux distribution you choose also makes a difference as some of them use different service management frameworks by default. I personally tend to like upstart, it has simple straight forward config files, and is also there by default in Ubuntu. Take a look at this blog(not mine) it gives a great overview of some of the different options.
Welcome to wild world of Linux, it may seem weird at first, but it's really fun!

Python Script to manage dns in Active Directory

What I want to do is write an Application in Python and deploy it in django(I want to implement it on Linux platform), and that Application could manage DNS remotely in Active Directory(Windows environment).
It's preferred that all the scripts written in Cpython.
I tryed several ways below but failed:
Use a module called dnspython, but it seem only work with BIND DNS, that still doesn't support Window DNS.
Use pywin32 module to invoke WMI, but pywin32 is a module only for Windows platform and failed to work in Linux.
Use Ironpython, it is the only workaround I get, but not so good because all other applications will be in Cpython.
Can somebody provide a resolution? Or a workaround.
In my understand, I need a cpython scripts run in Linux that could remotely manage DNS in Active Directory on Windows platform.
If there is any problem about it, please let me know.
Any suggestions are appreciated.
Set up the windows machine as a chaching nameserver, with the linux box as its authoritative nameserver. That way you can just change the settings of BIND on the linux box, and the windows box should follow along.
This question probably belongs on server fault, though.

Is it possible to deploy a Python application on the Mac App Store?

Does Apple accept Python applications for distribution on the new Mac App Store?
If so, how should the application be packaged? Is py2app sufficient? Something else?
I packaged Pennywise, which is available on the Mac App Store. It's based on Virgil's moneyGuru, which uses Python, PyObjC, and py2app.
You will have to follow Apple's process for preparing an application for submission to the Mac App Store. Most importantly, you will want to add the proper keys to your Info.plist, and remove any automatic updating mechanism, e.g. Sparkle. It's not strictly required, but you will probably also want to implement receipt checking. Using Xcode will make the submission process much easier. You can look at the moneyGuru source code for an example of how to use Xcode as the final part of the build process.
Py2app embeds a copy of the Python framework in the bundle, so I don't know whether Apple would approve an application that only linked to the system framework. While the primary binary can't support PPC, Apple does not seem to check the architectures of binaries in embedded frameworks.
One final caveat: I wouldn't recommend this process for writing new applications. Using Python, PyObjC, and py2app seriously complicates the build process and introduces additional dependencies.
I know it's possible because I know of at least one Python-based app that is in the app store ("Pennywise", which is based on my own app, moneyGuru, which uses Python + PyObjc + py2app). I didn't do it myself, so I'm not sure of the details.
I wrote a comprehensive article explaining how to build and submit a Python app to the Mac App Store. It includes source code and build scripts for a barebones example app that I have successfully submitted.
Submitting a Python App to the Mac App Store
Yes, it is possible, as long as you adhere with the full set of approval guidelines. This means that the python interpreter will have to be bundled into your application, for example.
See here for a full list of requirements:
https://developer.apple.com/appstore/mac/resources/approval/guidelines.html
It is quite possible. My app is currently listed:
http://itunes.apple.com/us/app/quickwho/id419483981?mt=12&ls=1#
Bundled up with py2app, no worries.
Apple provides the Build Applet tool for Python with Xcode so it should be supported by the App store. MacOS X 10.6.6 includes Python 2.5 and 2.6 as part of the default install, you can specify /usr/bin/python2.5 and /usr/lib/python2.5.

What are some successful methods for deploying a Django application on the desktop?

I have a Django application that I would like to deploy to the desktop. I have read a little on this and see that one way is to use freeze. I have used this with varying success in the past for Python applications, but am not convinced it is the best approach for a Django application.
My questions are: what are some successful methods you have used for deploying Django applications? Is there a de facto standard method? Have you hit any dead ends? I need a cross platform solution.
I did this a couple years ago for a Django app running as a local daemon. It was launched by Twisted and wrapped by py2app for Mac and py2exe for Windows. There was both a browser as well as an Air front-end hitting it. It worked pretty well for the most part but I didn't get to deploy it out in the wild because the larger project got postponed. It's been a while and I'm a bit rusty on the details, but here are a few tips:
IIRC, the most problematic thing was Python loading C extensions. I had an Intel assembler module written with C "asm" commands that I needed to load to get low-level system data. That took a while to get working across both platforms. If you can, try to avoid C extensions.
You'll definitely need an installer. Most likely the app will end up running in the background, so you'll need to mark it as a Windows service, Unix daemon, or Mac launchd application.
In your installer you'll want to provide a way to locate a free local TCP port. You may have to write a little stub routine that the installer runs or use the installer's built-in scripting facility to find a port that hasn't been taken and save it to a config file. You then load the config file inside your settings.py and whatever front-end you're going to deploy. That's the shared port. Or you could just pick a random number and hope no other service on the desktop steps on your toes :-)
If your front-end and back-end are separate apps then you'll need to design an API for them to talk to each other. Make sure you provide a flag to return the data in both raw and human-readable form. It really helps in debugging.
If you want Django to be able to send notifications to the user, you'll want to integrate with something like Growl or get Python for Windows extensions so you can bring up toaster pop-up notifications.
You'll probably want to stick with SQLite for database in which case you'll want to make sure you use semaphores to tackle multiple requests vying for the database (or any other shared resource). If your app is accessed via a browser users can have multiple windows open and hit the app at the same time. If using a custom front-end (native, Air, etc...) then you can control how many instances are running at a given time so it won't be as much of an issue.
You'll also want some sort of access to local system logging facilities since the app will be running in the background and make sure you trap all your exceptions and route it into the syslog. A big hassle was debugging Windows service startup issues. It would have been impossible without system logging.
Be careful about hardcoded paths if you want to stay cross-platform. You may have to rely on the installer to write a config file entry with the actual installation path which you'll have to load up at startup.
Test actual deployment especially across a variety of firewalls. Some of the desktop firewalls get pretty aggressive about blocking access to network services that accept incoming requests.
That's all I can think of. Hope it helps.
If you want a good solution, you should give up on making it cross platform. Your code should all be portable, but your deployment - almost by definition - needs to be platform-specific.
I would recommend using py2exe on Windows, py2app on MacOS X, and building deb packages for Ubuntu with a .desktop file in the right place in the package for an entry to show up in the user's menu. Unfortunately for the last option there's no convenient 'py2deb' or 'py2xdg', but it's pretty easy to make the relevant text file by hand.
And of course, I'd recommend bundling in Twisted as your web server for making the application easily self-contained :).

Setting up a Python web development environment on OS X

I'm running Mac OS X Leopard and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the future.
I've been trying to get mod_wsgi installed and configured to work with Django and have a headache now. Are there any web hosts that currently use mod_wsgi besides Google, so I could just develop there?
FWIW, we've found virtualenv [http://pypi.python.org/pypi/virtualenv] to be an invaluable part of our dev setup. We typically work on multiple projects that use different versions of Python libraries etc. It's very difficult to do this on one machine without some way to provide a localized, customized Python environment, as virtualenv does.
Most Python applications are moving away from mod_python. It can vary by framework or provider, but most development effort is going into mod_wsgi.
Using the WSGI standard will make your Python application server agnostic, and allow for other nice additions like WSGI middleware. Other providers may only provide CGI (which won't scale well performance wise), or FastCGI.
I've worked with Django using only the included server in the manager.py script and have not had any trouble moving to a production environment.
If you put your application in a host that does the environment configuration for you (like WebFaction) you should not have problems moving from development to production.
I run a Linux virtual machine on my Mac laptop. This allows me to keep my development environment and production environments perfectly in sync (and make snapshots for easy experimentation / rollback). I've found VMWare Fusion works the best, but there are free open source alternatives such as VirtualBox if you just want to get your feet wet.
I share the source folders from the guest Linux operating system on my Mac and edit them with the Mac source editor of my choosing (I use Eclipse / PyDev because the otherwise excellent TextMate doesn't deal well with Chinese text yet). I've documented the software setup for the guest Linux operating system here; it's optimized for serving multiple Django applications (including geodjango).
For extra added fun, you can edit your Mac's /etc/hosts file to make yourdomainname.com resolve to your guest Linux boxes internal IP address and have a simple way to work on / test multiple web projects online or offline without too much hassle.
What you're looking for is Mod_Python. It's an Apache-based interpreter for Python. Check it out here:
http://www.modpython.org/
Google App Engine has done it for you. Some limitations but it works great, and it gives you a path to hosting free.
Of course Mac OS X, in recent versions, comes with Python and Apache. However you may want to have more flexibility in the versions you use, or you may not like the tweaks Apple has made to the way they are configured. A good way to get a more generic set of tools, including MySQL, is to install them anew. This will help your portability issues. The frameworks can be installed relatively easily with one of these open source package providers.
Fink
MacPorts
MAMP
mod_wsgi is really, really simple.
Pyerweb is a really simple (~90 lines including comments/whitespace) WSGI-compliant routing-framework I wrote. Basically the WSGI API is just a function that gets passed environ, and wsgi_start_response, and it returns a string.
envrion is a dict with the request info, for example environ['PATH_INFO'] is the request URI)
wsgi_start_response which is a callable function which you execute to set the headers,:
wsgi_start_response(output_response, output_headers)
output_response is the string containing the HTTP status you wish to send (200 OK etc), and output_headers is a list-of-tuples containing your headers (for example, [("Content-type", "text/html")] would set the content-type)
Then the function returns a string containing your output.. That's all there is to it!
To run it, using spawning you can just do spawn scriptname.my_wsgi_function_nae and it will start listening on port 8080.
To use it via mod_wsgi, it's documentation is good, http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide and there is a django specific section
The up-side to using mod_wsgi is it's the standard for serving Python web-applications. I recently decided to play with Google App Engine, and was surprised when Pyerweb (which I linked to at the start of this answer) worked perfectly on it, completely unintentionally. I was even more impressed when I noticed Django applications run on it too.. Standardisation is a good thing!
You may want to look into web2py. It includes an administration interface to develop via your browser. All you need in one package, including Python.
Check out WebFaction—although I don't use them (nor am I related to / profit from their business in any way). I've read over and over how great their service is and particularly how Django-friendly they are. There's a specific post in their forums about getting up and running with Django and mod_wsgi.
Like others before me in this thread, I highly recommend using Ian Bicking's virtualenv to isolate your development environment; there's a dedicated page in the mod_wsgi documentation for exactly that sort of setup.
I'd also urge you to check out pip, which is basically a smarter easy_install which knows about virtualenv. Pip does two really nice things for virtualenv-style development:
Knows how to install from source control (SVN, Git, etc...)
Knows how to "freeze" an existing development environement's requirements so that you can create that environment somewhere else—very very nice for multiple developers or deployment.

Categories