ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
That will prompt for a password and install packages from download_folder
How can I do this in a way where I could prompt for the password and then send the password in where it's needed. I can't seem to get the syntax right to use pipe, and popen tells me that su must be run in a terminal.
You just want to put in your password once and then it installs everything else right? I'd guess that because your in the for loop your getting prompted for the password everytime. Did you try putting the su -c outside of the for loop:
Code:
packages = os.listdir(download_folder)
os.system("su -")
# it will prompt you for your password
for pkg in packages:
cmd = "upgradepkg --install-new " + download_folder + "/" + pkg
os.system(cmd)
I haven't tested this out and it may not work but its just a thought.
I'va already done similar things, but that's not what I was looking for. The rest of my program get all user input using dialog. I want to avoid using the console and run the command in a pipe of some type.
def install_downloaded_pkgs(d):
global download_folder
global desc_folder
downloaded = os.listdir(download_folder)
if len(downloaded) == 0:
d.infobox("Download folder is empty")
return
if len(downloaded) > 0:
heading = "Choose package(s) to Install"
maxLen = len(heading)
downloaded_list = []
for dl in downloaded:
if len(dl) > maxLen: maxLen = len(dl)
downloaded_list.append((dl,"",0))
inst_choice = d.checklist(heading,downloaded_list,maxLen+12,len(downloaded)+6,len(downloaded))
if len(inst_choice) > 0:
print "Installing packages requires root access."
print "Please enter your password."
inst_cmd = "su -c 'upgradepkg --install-new"
for pkg in inst_choice:
inst_cmd += " " + download_folder + "/" + pkg
inst_cmd += "'"
os.system(inst_cmd)
inst_pkglist = get_installed_pkgs(d)
os.unlink(inst_path)
output = open(inst_path,'w')
for pkg in inst_pkglist:
output.write(str(pkg) + "\n")
output.close()
return
The above code uses a dialog class that I wrote to get all input/output using the linux dialog utility. The only time the program dumps the user back to the console is when installing packages. I want to prompt the user for a password and show the user the package description file while the file is being installed.
What I want.
Code:
def install_downloaded_pkgs(d):
global download_folder
global desc_folder
global inst_path
downloaded = os.listdir(download_folder)
if len(downloaded) == 0:
d.infobox("Download folder is empty")
return
if len(downloaded) > 0:
heading = "Choose package(s) to Install"
maxLen = len(heading)
downloaded_list = []
for dl in downloaded:
if len(dl) > maxLen: maxLen = len(dl)
downloaded_list.append((dl,"",0))
inst_choice = d.checklist(heading,downloaded_list,maxLen+12,len(downloaded)+6,len(downloaded))
if len(inst_choice) > 0:
msg = "Installing packages requires root access.\n"
msg += "Please enter your password."
while 1:
pw = d.passwordbox(msg,40,10,1)
if pw != "": break
for pkg in inst_choice:
descFile = desc_folder + "/" + pkg.replace(".tgz",".txt")
been_inst_path = "/var/log/packages/" + pkg.replace(".tgz","")
d.infobox(descFile,100,20)
inst_cmd += "su -c 'upgradepkg --install-new " + download_folder + "/" + pkg + "'"
# need commands here to send inst_cmd + pw
# want to run in background
while 1:
if os.path.exists(been_inst_path): break
time.sleep(0.5)
inst_pkglist = get_installed_pkgs(d)
os.unlink(inst_path)
output = open(inst_path,'w')
for pkg in inst_pkglist:
output.write(str(pkg) + "\n")
output.close()
return
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.