Page 1 of 1

session_setup & copy user profile file

Published: June 4, 2019 - 09:33
by vandatt
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?

Re: session_setup & copying user profile file

Published: June 4, 2019 - 12:21
by dcardon
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

Re: session_setup & copying user profile file

Published: June 4, 2019 - 12:54 PM
by vandatt
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)

Re: session_setup & copying user profile file

Published: June 12, 2019 - 2:21 PM
by jeancharles
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!

Re: session_setup & copying user profile file

Published: June 21, 2019 - 1:01 PM
by dcardon
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