Python prgram won't buil d after renaming it - python

I've setup Geany a long time ago to compile my Python program on my Windows machine which it then sends to my Pi via scp. It still works fine - but if I take the same file and rename it, it refuses to do it.
I get "scp: /home/pi/scripts/APC2.py: Permission denied" from the Compiler in the MEssage window
And really don't want all my programs called the same thing.
I basically can't remember how I did the setup and can't find it anywhere on the internet.
Any help will be greatly appreciated

I found the link again:
http://www.python-exemplary.com/index_en.php?inhalt_links=navigation_en.inc.php&inhalt_mitte=raspi/en/installation.inc.php
Also my permissions for the new file were incorrect as Geany sends the file to /home/pi/scripts and I log in as root and not the pi user.

Related

Cannot get Perforce Triggers to work properly

Been trying to get this working all day, and i just can't figure out why its not working.
Trying to implement a simple trigger to run when the user submitted a file.
example in the .tmp file:
hello_trigger change-submit //testDepot/... "python F:/triggers/hello_trigger.py"
when i try to submit a file i get this:
Submit validation failed -- fix problems then use 'p4 submit -c 10199'.
'hello_trigger' validation failed: python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
File exists and can be read, so its not a python issue.. same error with a .txt or .bat file.
From what i can gather the problem seems to be coming from the depot line in the trigger.
//testDepot/... fails
//depot/... doesnt fail, but the script is never fired off.
Any suggestions are greatly appreciated.
also testDepot is a stream not sure if that matters.
python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
seems pretty clear that the file doesn't exist, at least from the point of view of this trigger command. Some things to double check:
This is running on the server machine, i.e. the place where the p4d service is running. If you have the script on your client machine the Python executable on the server isn't going to be able to find it!
Similarly, this is being run by whatever user is running p4d (on Windows this is usually the SYSTEM user, which may have limited permissions). Does that user have permission to read this path?
Could it be that your version of Python on Windows doesn't know how to handle paths with Unix-style forward slashes? (Many tools will normalize these for you but you shouldn't depend on it!) Try using a valid Windows path, i.e. F:\triggers\hello_trigger.py.

Windows file starting with dot raises PermissionError?

I have a program (written in Python3.6, transformed into an .exe for Windows using cx_Freeze) that uses a lock-file to mark whether a user-login is currently in use, to allow the use of the same login across multiple computers while avoiding possible database corruptions.
The file is created right after the user login is confirmed (and deleted when the user logs out):
lockfile = os.path.join(user_dir, ".locked")
with open(lockfile, "w") as _:
os.utime(lockfile)
On my Windows7 Professional machine, this works fine. It also works fine on my local Windows10 test machine.
Now, I have a client on a remote location who is trying to use the program. And apparently, they consistently get a Permission Error: [Errno 13] Permission denied: '<user_dir>\.locked'. (Their path seems valid, and the program has no problem creating the user_dir, or writing a config.ini file to it, so writing privileges on the directory should not be the issue.)
Do some Windows versions maybe have trouble with files starting with a dot? Could using an underscore etc. instead help?
The client uses Windows10 (Enterprise) Version 1809 (Build 17763.379).
(It's hard to debug from here, and as I have to recompile the installer after every change, it would be nice to have an idea if this even makes sense... Any other thoughts about potential sources of the problem are welcome, as well!)
Apparently, it really was the starting dot colliding with some (but not all) Windows versions. I created a new version where the file is named "_locked" and it works fine now.
According to this article, creating filenames starting with dots is only added to Windows 10 1903:
https://www.ghacks.net/2019/02/25/windows-10-1903-support-for-filenames-and-folders-with-beginning-dot-character/
Had similar experience with Windows server 2019 where it was at least impossible to add .files via the file explorer. Workaround was to create the files via PowerShell, though I guess that doesn't really help here. :|

Uploading Motion Files to Google Drive using Raspbian and Raspberry Pi

I've been playing around with Motion on my Rapsberry Pi running Raspbian and came across this post that sounded like fun to do.
I've been trying to tweak the steps he lists to have it work with Raspbian, and as far as I know I should be good. I installed GData using "sudo apt-get install python-gdata" And then I put the uploader.py and uploader.cfg files in /etc/motion and changed the motion.confg file to have the line
on_movie_end /etc/motion/uploader.py /etc/motion/uploader.cfg %f
Am I missing something? Theoretically this should work on Raspbian right? What else has to be done?
Thanks
I have been following the guides you have referred to get this working on Raspbian and I had the same problem; Motion seems to work but the script never executes.
However, when i tried to run the script directly I got a permission error.
I ran the following to make the script executable.
chmod a+x /etc/motion/uploader.py
now it uploads the videos to Google drive (no emails though?)
hope this helps,
This isn't a direct answer to your question, but it might be a away of getting files uploaded to google drive in an easier way.
Have you had a look at grive, its a linux utility which can be used to sync a folder on your raspberry pi with a folder on google drive.
See this link for more info on how to setup and use grive on a raspberry pi.
http://www.stuffaboutcode.com/2013/03/raspberry-pi-google-drive-grive.html
I also struggled with it quite a bit and this is what helped. First try to run this from terminal:
/etc/motion/uploader.py /etc/motion/uploader.cfg /
Here you put the absolute path to your file you want to upload.
Try to run it, and if it asks you for a password you know you have a permission problem and need to change permissions so that it does not require the password to execute.
Try again. If it works then it will also work if you use this in uploader.cfg:
on_movie_end /etc/motion/uploader.py /etc/motion/uploader.cfg %f
Do not forget to uncomment this line! This sounds silly but it took me some time to realize it, i.e. delete ; that is in front of on_movie_end.
Another issue I had was the movie encoding. Only mpeg4 really worked for me.

Python's (version 2.7.2) Idle does not execute any commands (command prompt works fine!!)

I'm trying to run python (version 2.7.2) on my computer (windows vista 32bit). It's always worked until now when Idle just does not respond to any commands.
Any commands entered (even very simple ones) have no output/do not get computed! See image:
Python works fine when I run it using command line though!
I've tried re-installing it a few times but it just doesn't help! Also tried running it from C:\Python27\Lib\idlelib\idle.py and I get the following message before the same unresponsive IDLE pops up again! See image:
Any help would be greatly appreciated.
Thanks
Try
print 1+2
You need to do something with the result.
A few suggestions:
IDLE starts a subprocess and connects to it over TCP port 8833. Is this port being blocked by a firewall on your computer?
Are there any files whose name clash with built-in Python modules? This page mentions problems with files called string.py.
Is the file config-keys.def under C:\Python27\Lib\idlelib missing or does it have its permissions set so that nobody can read it? I found that if I removed this file or restricted the permissions on it, IDLE became unresponsive as you described. If I then replaced it or reset the permissions, IDLE started working again. (Other config-*.def files in this folder might also need to be checked.)
This looks like the bug described here: http://bugs.python.org/issue14409
Your config file for key bindings is corrupt. Try renaming your ~/.idlerc folder to something else and restart IDLE.

How do I add a python script to the startup registry?

I'm trying to make my python script run upon startup but I get the error message windowserror access denied, but I should be able to make programs start upon boot because teamviewer ( a third-party program I downloaded ) runs every time I restart my computer so I know that I should be able to make my program run at startup (I might be doing something different though, so if you could shed some light on what teamviewer is doing differently to get its script to run at startup that would be helpful).
Here is my script
import _winreg, webbrowser
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Run')
_winreg.SetValueEx(key,'pytest',0,_winreg.REG_BINARY,'C:\Users\"USERNAME"\Desktop\test.py')
key.Close()
webbrowser.open('www.youtube.com')
Any input is appreciated.
import webbrowser
webbrowser.open('www.youtube.com')
Get rid of all of that _winreg stuff. Instead, you (assuming double-clicking on a py file opens the console) should simply place it in your startup folder (C:\Users\yourusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup on Windows 7, and C:\Documents and Settings\yourusername\Start Menu\Programs\Startup in XP). This works because Windows tries to open all files in the startup folder, and if Python opens PYs by default, Windows will open the Python console. Try restarting, that should work.
Baboon:
I am a little late posting, but you seem to have left off the sam at the end of your code here.
When you open a key you need to add the user rights, if you do not _winreg defaults to "READ":
Here is a snippet from the python site
http://docs.python.org/2/library/_winreg.html#access-rights
sam is an integer that specifies an access mask that describes the desired security access for the key. Default is KEY_READ. See Access Rights for other allowed values.
Here is the code corrected:
import _winreg, webbrowser
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Run',_winreg.KEY_SET_VALUE)
_winreg.SetValueEx(key,'pytest',0,_winreg.REG_BINARY,'C:\Users\"USERNAME"\Desktop\test.py')
key.Close()
webbrowser.open('www.youtube.com')

Categories

Resources