session_setup & copy user profile file

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
vandatt
Messages: 10
Registration: Nov 30, 2018 - 11:44

June 4, 2019 - 09:33

Hello,

I've been trying for a few days to copy a folder (after a software installation) to the user profile of the person logged into a computer.
I've tried using `%get_current_user()` or `%username%`, but neither command is interpreted.

Has anyone else encountered this problem?
User avatar
dcardon
WAPT Expert
Messages: 1929
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

June 4, 2019 - 12:21

Hello vandatt,
vandatt wrote: June 4, 2019 - 9:33 AM For a few days now, I've been trying to copy a folder (after a software installation) to the user profile of the person logged into a computer.
I've tried using %get_current_user() or %username%, but neither command is interpreted.

Has anyone else encountered this problem?
Could you post the code from your setup.py file? It will be easier to give feedback that way.

In any case, %username% is a Windows environment variable, not a Python variable or command, and it is better to remove the % before get_current_user(), the % probably refers in your case to a string substitution, and is not part of the function name.

Sincerely,

Denis
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
vandatt
Messages: 10
Registration: Nov 30, 2018 - 11:44

June 4, 2019 - 12:54

Hello,

Here is my latest attempt:

def session_setup():
util=get_current_user()

def install():
chemin = ('c:\\Users\\'+util+'\\AppData\\Roaming\XX')
copytree2('C\\Users\Default\\Appdata\\Roaming\\XX',chemin)
jeancharles
Messages: 21
Registration: June 11, 2019 - 10:02

June 12, 2019 - 2:21 PM

There seem to be some typos in the code

: `util=get_curent_user()` --> `get_curRent_user` with a second `R`. `

chemin = ('c:\\Users\\'+util+'\\AppData\\Roaming\XX')` `
copytree2('C\\Users\Default\\AppData\\Roaming\\XX',chemin)` --> the colon is missing, unless I'm mistaken.

As for the rest, I'm not any better, sorry!
User avatar
dcardon
WAPT Expert
Messages: 1929
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

June 21, 2019 - 1:01 PM

Hello Vandatt,

It's best to put the code between code tags; it makes it easier to read:

Code: Select all

// A NE PAS PRENDRE COMME EXEMPLE!!
def session_setup():  
   util=get_current_user()

def install():
  chemin = (r'c:\Users\'+util+'\AppData\Roaming\XX')
  copytree2(r'C:\Users\Default\Appdata\Roaming\XX',chemin)
then the variable get_current_user() was misspelled (as Jean-Charles mentioned).

If you have backslashes \ in your string, you can add an "r" in front of the string to indicate that you are in raw string mode in Python. This avoids doubling the backslashes and therefore forgetting them in your string (2 places)

The `def session_setup()` function and the `def install()` function are called at two different times and in two different contexts. The `util` variable will never be populated as your code is currently written.

I encourage you to reread the documentation https://www.wapt.fr/fr/doc/wapt-create- ... index.html and to take a look at https://store.wapt.fr/store/details-tis ... 4_all.wapt And for a more extreme example, https://store.wapt.fr/store/details-tis ... l_all.wapt .

Sincerely,

Denis
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
Locked