[Solved] Moving desktop shortcut

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

November 22, 2015 - 8:43 AM

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?
Attachments
error.jpg
error.jpg (103.07 KB) Viewed 5858 times
Last edited by gaelds on 23 Nov 2015 - 12:40, edited 1 time.
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

November 22, 2015 - 9:35 AM

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.
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

November 23, 2015 - 09:07

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'))
Tranquil IT
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

November 23, 2015 - 09:23

Thanks a lot! I'll test it soon. The second code should also work on XP?
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

November 23, 2015 - 11:30

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?
Picture
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

November 23, 2015 - 12:09

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`).
Tranquil IT
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

November 23, 2015 - 12:39

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!
Locked