I have a Digi ConnectPort X4 here and I am going to run a simple web server on it to serve the information from the ZigBee network that is attached.
The HTTPBaseServer and subclasses are pure Python classes, but I also want to have some kind of database running on the device. As I don't need to have complex functionality, I thought I would try to get PySQLite running on this embedded box.
However, as it turns out, I cannot use GCC on this box, so is there any other possibiliy to get some kind of database functionality on this box? Or did I miss a possibility to get that SQLite adapter on this box?
Someone must have had a compiler to make Python. A compiler is required to get (py)sqlite working.
You may be able to use the db/anydbm module instead which will use a flavour of dbm or a pure Python alternative. This won't give you a SQL database, but will give you a key value store which is likely good enough for your needs.
I am in the same situation as you. You can make yourself a pseudo DB with some tuples, or in my case some dictionarys. Something like that:
pseudoDB={}
pseudoDB[1]={'id':1, 'zb-dev-object':ZB_object, 'power':power_value} #and so on
Related
I have to setup a program which reads in some parameters from a widget/gui, calculates some stuff based on database values and the input, and finally sends some ascii files via ftp to remote servers.
In general, I would suggest a python program to do the tasks. Write a Qt widget as a gui (interactively changing views, putting numbers into tables, setting up check boxes, switching between various layers - never done something as complex in python, but some experience in IDL with event handling etc), set up data classes that have unctions, both to create the ascii files with the given convention, and to send the files via ftp to some remote server.
However, since my company is a bunch of Windows users, each sitting at their personal desktop, installing python and all necessary libraries on each individual machine would be a pain in the ass.
In addition, in a future version the program is supposed to become smart and do some optimization 24/7. Therefore, it makes sense to put it to a server. As I personally rather use Linux, the server is already set up using Ubuntu server.
The idea is now to run my application on the server. But how can the users access and control the program?
The easiest way for everybody to access something like a common control panel would be a browser I guess. I have to make sure only one person at a time is sending signals to the same units at a time, but that should be doable via flags in the database.
After some google-ing, next to QtWebKit, django seems to the first choice for such a task. But...
Can I run a full fledged python program underneath my web application? Is django the right tool to do so?
As mentioned previously, in the (intermediate) future ( ~1 year), we might have to implement some computational expensive tasks. Is it then also possible to utilize C as it is within normal python?
Another question I have is on the development. In order to become productive, we have to advance in small steps. Can I first create regular python classes, which later on can be imported to my web application? (Same question applies for widgets / QT?)
Finally: Is there a better way to go? Any standards, any references?
Django is a good candidate for the website, however:
It is not a good idea to run heavy functionality from a website. it should happen in a separate process.
All functions should be asynchronous, I.E. You should never wait for something to complete.
I would personally recommend writing a separate process with a message queue and the website would only ask that process for statuses and always display a result immediatly to the user
You can use ajax so that the browser will always have the latest result.
ZeroMQ or Celery are useful for implementing the functionality.
You can implement functionality in C pretty easily. I recomment however that you write that functionality as pure c with a SWIG wrapper rather that writing it as an extension module for python. That way the functionality will be portable and not dependent on the python website.
I've successfully written a Powershell script which:
query AD to obtain the list of computer
query every computer through WMI to obtain software/hardware information
insert the collected data into a MySQL database.
The script works fine but I don't like how it's implemented. It's procedural and there is a lot of code duplication, causing a mess everytime I need to change something.
Now, what I would like to ask you is: what is the cleanest way to implement it in python using OOP? I've thought something similar to this (pseudocode):
Class ADquery
function get_computers( UO ): return a list of computers in the specified UO
Class Computer
constructor( computername )
function query(): connect to the computer and pull the info through WMI
function print(): print the collected info to the console (debug)
property RAM
property CPU
...
Questions:
In order to save the collected data into a Database, do I have to create another object (e.g. Database) and pass the Computer object to him or add a member function to the Computer class (e.g. save_db() ) ?
If I go for the second option, that wouldn't cause a massive number of MySQL connections when I'm dealing with multiple objects?
Thanks a lot and sorry for my bad English
That architecture looks reasonable to me.
You could do either, I'm not sure it really makes a huge difference with a small application like this.
Potentially. Depending on how it's implemented you could get a lot of connections going on. If you're doing a reasonable number of inserts I'd stick them in a list and insert all at once, if that's possible with your code.
You could also grab an Object Oriented Design book from the internet or your local bookstore, e.g. Rumbaugh et al.. I would also recommend reading up on Design Patterns, e.g. the book by Gamma et. al.. I'm currently doing that, and it is really helpful to look at standard patterns of how to solve a particular problem to shape your thought process about object oriented programming.
ps Your English isn't bad at all (note that I'm also not a native speaker ;)).
I have a working GPIB interface and Linux-GPIB package installed and working.
I only know two commands at the moment, x.write and x.find. I don't know much about Python, but I recognize the dot operator and realize that after importing gpib, I should get some functions at my disposal.
I have not been able to locate the list of GPIB functions.
They are in the gpib library. You reference them like so: gpib.foo().
Add this line into your code:
help(gpib)
And browse through the functions/classes.
If you are working in Python, I think the pyvisa is what you are looking for. It provides lots of useful high level functions which helps you to send a series of SCPI commands to your equipment via GPIB, such as write, read,ask and so on.
As for SCPI commands themselves, usually they will differ from the different vendors. So in terms of what kind of SCPI you should send to the equipment, you should read the corresponding datasheet. But in the other case, you could have installed the drivers which were provided by the vendor. In this case you can send some even higher commands. For instance, if you would like to control a voltage source, they have probably already got the function setvoltage(double voltage). Things will be much more easier for you.
Actually there are many commands available. Except those two you mentioned, there are x.read, x.ask, x.ask_for_value and so on.
But I recommend your to read those help file, I think that will give you a better understanding.
Is it possible to make python run on your homepage? I know, this is a really stupid question but please don't pick on me for my stupidity :)
If it is possible, how? Do you have to upload/install the executing part of Python to you website using FTP? or...?
Edit: Just found out my provider does not support python and that shell access is completely restricted. Problem solved :)
Everything depends on the hosting provider you use for your homepage -- do they offer Python among their services, and, if so, what version, and how do you write server-side scripts to use it (is it CGI-only, or...?) -- if not, or the version / deployment options disappoint, what do they allow in terms of giving you shell access and running long-time processes?
It's impossible for us to judge any of these aspects, because every single one of them depends on your hosting provider, and absolutely none of them depends on Python itself!-)
Yes, you can. I don't know exactly how but I know it is possible. Mabye look into this website:
https://trinket.io/
This website lets you do this. I sent them a message to see how they do it so I will update this to let you know after they respond.
Python is a scripting language, though it is used gracefully for building back end web applications.
Recently I've found myself testing an aplication in Froglogic's Squish, using Python to create test scripts. Just the other day, the question of how much memory the program is using has come up, and I've found myself unable to answer it.
It seems reasonable to assume that there's a way to query the os (windows 7) API for the information, but I've no idea where to begin. Does anyone know how I'd go about this?
this answer has some code (for windows and unix):
Total memory used by Python process?
on win, you are checking Win32_PerfRawData_PerfProc_Process and on linux it's /proc/pid/status (or ps)
Remember that Squish allows remote testing of the application. A system parameter queried via Python directly will only apply to the case of local testing.
An approach that works in either case is to call the currentApplicationContext() function that will give you a handle to the Application Under Test. It has a usedMemory property you can query. I don't recall which process property exactly is being queried but it should provide a rough indication.
In command line: tasklist /FO LIST and parse the results?
Sorry, I don't know a Pythonic way. =P