Make one time only activation code to python code, and make updates available? - python-3.x

I'm coding a program to do some action with webdriver and Autoit in python, I want to do two things before I start selling my code:
Add onetime activation code to my software on one PC, like to make the program works only on one pc.
Make my program able to receive updates from the internet once I add to the code some more features or correct some others.
is it possible only with Python? or what is the method statement to do it?

On client side you need use hard-disk serial or/and uuid of partition or Operational System timestamp + something to generate serial code .
On server side , you need a API to store hard disk serial to validate if this is a computer valid . And you client on load check if activaction is valid .
The second question i can't answer .

Regarding the second part of your question:
Create a text file with the latest version of your application and put it on your webserver e.g. http://download.example.com/example-app-version.txt to get and read its value later.
On your python code download and read the text (for Python 3+ use 'import urllib.request' and urllib.request.urlretrieve) when your app runs and compare it against the installed version (if statement).
E.g.
if latestVer > installedVer:
#update
else:
#application continues

Related

How to pass "yes/no" to prompt from python code?

I have tiny little python code which logs in to a remote machine and gets the output of a command and prints to a file..
Here for a particular command, the server asks for Y or N, how do i pass an Yes to it and get the desired output?
Here is the sample output from the server:
root#nnodee11cc40c:/home/usr/redsuren# controlport rst 0:3:3
WARNING: Port 0:3:3 may have active Smart SAN target driven zones that may be disrupted. If changing the port configuration, remove the Smart SAN zoning by using the removehost command. This must be done before changing the port configuration; otherwise, you will not be able to manage the zone on the switch associated with this port.
Are you sure you want to run controlport rst on port 0:3:3?
select q=quit y=yes n=no: ---------> Here i have to tell the program to enter y
How can I achieve this?
Thanks!!
If I understand your question correctly, you need to automate pressing 'y' & 'enter' with Python. You can easily do this by PyAutoGui.
First, execute pip install pyautogui in the command prompt.
Then import it to your code by using import pyautogui
Now for achieving this you have to put the following code where you want to press 'y' & 'enter':
pyautogui.press('y')
pyautogui.press('enter')
But this may not be timed according to when it asks so you may need to time it yourself
by adding time.sleep(<numberOfSeconds>) after importing it by import time
Now here is the full answer:
import pyautogui, time
# Your code here
time.sleep(3)
pyautogui.press('y')
pyautogui.press('enter')
But if my answer is not what you asked for, then you have to give us your code so we can understand your question better thus answer it to your needs.

How to get SMAC3 working for Python 3x on Windows

This is a great package for Bayesian optimization of hyperparameters (especially mixed integer/continuous/categorical...and has shown to be better than Spearmint in benchmarks). However, clearly it is meant for Linux. What do I do...?
First you need to download swig.exe (the whole package) and unzip it. Then drop it somewhere and add the folder to path so that the installer for SMAC3 can call swig.exe.
Next, the Resource module is going to cause issues because that is only meant for Linux. That is specifically used by Pynisher. You'll need to comment out import pynisher in the execute_func.py module. Then, set use_pynisher:bool=False in the def __init__(self...) in the same module. The default is true.
Then, go down to the middle of the module where an if self.use_pynisher....else statement exists. Obviously our code now enters the else part, but it is not setup correctly. Change result = self.ta(config, **obj_kwargs) to result = self.ta(list(config.get_dictionary().values())). This part may need to be adjusted yet depending on what kind of inputs your function handles, but essentially you can see that this will enable the basic example shown in the included branin_fmin.py module. If doing the random forest example, don't change at all...etc.

Can you read the length of an mp3 file in python 3 on windows 10?

I am currently creating a music player in python 3.3 and I have a way of opening the mp3/wav files, namely through using through 'os.startfile()', but, this way of running the files means that if I run more than one, the second cancels the first, and the third cancels the second, and so on and so forth, so I only end up running the last file. So, basically, I would like a way of reading the mp3 file length so that I can use 'time.sleep(SongLength)' between the start of each file.
Thanks in advance.
EDIT:
I forgot to mention, but I would prefer to do this using only pre-installed libraries, as i am hoping to publish this online as a part of a (much) larger program
i've managed to do this Using an external module, as after ages of trying to do it without any, i gave up and used tinytag, as it is easy to install and use.
Nothing you can do without external libraries, as far as I know. Try using pymad.
Use it like this:
import mad
SongFile = mad.MadFile("something.mp3")
SongLength = SongFile.total_time()

Can I alter Python source code while executing?

What I mean by this is:
I have a program. The end user is currently using it. I submit a new piece of source code and expect it to run as if it were always there?
I can't find an answer that specifically answers the point.
I'd like to be able to say, "extend" or add new features (rather than fix something that's already there on the fly) to the program without requiring a termination of the program (eg. Restart or exit).
Yes, you can definitely do that in python.
Although, it opens a security hole, so be very careful.
You can easily do this by setting up a "loader" class that can collect the source code you want it to use and then call the exec builtin function, just pass some python source code in and it will be evaluated.
Check the package
http://opensourcehacker.com/2011/11/08/sauna-reload-the-most-awesomely-named-python-package-ever/ . It allows to overcome certain raw edges of plain exec. Also it may be worth to check Dynamically reload a class definition in Python

Match a pid to an application desktop schema on Linux

All standards compliant applications in Linux store a desktop schema in /usr/share/applications/. In my particular use case, I have a WnckWindow data structure and I can get a pid from that. Using this pid, I can extract the command line from the proc.
Unfortunately, it seems that the proc command line entry does not match the desktop schema launch parameters. For example, the 'thunderbird' application is launched via /usr/bin/thunderbird but this is just a shell script which activates the real executable: /usr/lib/thunderbird-8.0/thunderbird-bin.
The real executable cannot be launched directly as it is dependent on the library paths configured in the /usr/bin/thunderbird script. Does anyone have any advice on how to match process id numbers to the appropriate desktop schema without getting caught by the issue I've described?, Thanks.
Ok, well, it appears that there's no nice way of solving this using the pid, however, it is relatively easy to match the Wnck windows class to application desktop schemas. The Wnck windows class needs to be preprocessed a little first to ensure that the filter works but it's pretty trivial stuff. Once you've got a good set of target strings, eg 'Thunderbird' or 'Google' + 'Chrome', you can use the system application menu API to zero in on a likely candidate, for example, by using garcon on Xfce.

Resources