Page 1 of 1
[Solved] Moving desktop shortcut
Published: November 22, 2015 - 8:43 AM
by gaelds
Good morning,
After installing Stellarium, I'd like to move the default desktop shortcut to a subfolder (after verifying that it already exists). Unfortunately, when I run the build-upload command, I get the following messages: FATAL ERROR: IOError: [Errno 2] No such file or directory...
Here is an excerpt from the code:
Code: Select all
if isdir("c:\Users\Public\Desktop\Logiciels\Physique-Chimie\""):
if isfile("c:\Users\Public\Desktop\Stellarium.lnk"):
print ('Déplacement du raccourci Stellarium')
shutil.move("c:\Users\Public\Desktop\Stellarium.lnk","c:\Users\Public\Desktop\Logiciels\Physique-Chimie\Stellarium.lnk")
The build-upload works if I create the file c:\Users\Public\Desktop\Logiciels\Physique-Chimie\Stellarium.lnk on my PC, but can this kind of error be avoided by modifying the code?
Re: Moving desktop shortcut
Published: November 22, 2015 - 09:35
by gaelds
Another problem is that the shortcut isn't moved when I test the package. Is there an error in the code? I tried adding a 30-second pause with `time.sleep(30)` before starting the move, but that didn't work either.
Re: Moving desktop shortcut
Published: November 23, 2015 - 09:07
by htouvet
add "r" characters (raw string) so that Python doesn't interpret the \
Code: Select all
if isdir(r"c:\Users\Public\Desktop\Logiciels\Physique-Chimie"):
if isfile(r"c:\Users\Public\Desktop\Stellarium.lnk"):
print (u'Déplacement du raccourci Stellarium')
shutil.move(r"c:\Users\Public\Desktop\Stellarium.lnk",r"c:\Users\Public\Desktop\Logiciels\Physique-Chimie\Stellarium.lnk")
to improve portability,
Code: Select all
if isdir(makepath(common_desktop(),'Logiciels','Physique-Chimie')) and isfile(common_desktop(),'Stellarium.lnk'):
print(u'Déplacement du raccourci Stellarium')
shutil.move(makepath(common_desktop(),'Stellarium.lnk'),makepath(common_desktop(),'Logiciels','Physique-Chimie','Stellarium.lnk'))
Re: Moving desktop shortcut
Published: November 23, 2015 - 09:23
by gaelds
Thanks a lot! I'll test it soon. The second code should also work on XP?
Re: Moving desktop shortcut
Published: November 23, 2015 - 11:30 AM
by gaelds
Sorry, it doesn't seem to be working; the shortcut remains on the desktop. Could the fact that the user (student) doesn't have write permissions on the shortcuts folder cause the error below?

Re: Moving desktop shortcut
Published: November 23, 2015 - 12:09 PM
by htouvet
The `install ext` procedure was executed under the system account. Therefore, there are no permissions issues.
The `shutil.move` function assumes the destination doesn't exist.
So, you need to check that the destination file doesn't exist... (`isfile`)
Also check that the folder exists; if not, create it (`mkdirs`).
Re: Moving desktop shortcut
Published: November 23, 2015 - 12:39
by gaelds
I finally got it working; the `makepath` command was missing from `isfile`. Below is the code that works on Windows 7 (not tested on XP). I don't know if the uninstall part is necessary...?
Code: Select all
if iswin64():
uninstallkey = ["Stellarium_is1"]
print ("Fermeture de Stellarium")
killalltasks('Stellarium.exe')
print('installation de dst-stellarium 64bits')
run(r'"stellarium-0.14.0-win64.exe" /VERYSILENT')
print ("Pause de 15sec.")
time.sleep(15)
if isdir(makepath(common_desktop(),'Logiciels','Physique-Chimie')) and isfile(makepath(common_desktop(),'Stellarium.lnk')):
print(u'Déplacement du raccourci Stellarium')
shutil.move(makepath(common_desktop(),'Stellarium.lnk'),makepath(common_desktop(),'Logiciels','Physique-Chimie','Stellarium.lnk'))
else:
uninstallkey = ["Stellarium_is1"]
print ("Fermeture de Stellarium")
killalltasks('Stellarium.exe')
print('Installation de dst-stellarium 32bits')
run(r'"stellarium-0.14.0-win32.exe" /VERYSILENT')
print ("Pause de 15sec.")
time.sleep(15)
if isdir(makepath(common_desktop(),'Logiciels','Physique-Chimie')) and isfile(common_desktop(),'Stellarium.lnk'):
print(u'Déplacement du raccourci Stellarium')
shutil.move(makepath(common_desktop(),'Stellarium.lnk'),makepath(common_desktop(),'Logiciels','Physique-Chimie','Stellarium.lnk'))
def uninstall():
killalltasks('Stellarium.exe')
print ("Désinstallation de Stellarium")
if isfile(makepath(common_desktop(),'Logiciels','Physique-Chimie','Stellarium.lnk')):
remove_file(makepath(common_desktop(),'Logiciels','Physique-Chimie','Stellarium.lnk'))
if isfile(makepath(common_desktop(),'Stellarium.lnk')):
remove_file(makepath(common_desktop(),'Stellarium.lnk'))
return (0);
Thank you for your help!