The Following C linux development packages are installed using python script:
import subprocess
import shutil
import os
APT_INSTALL_COMMAND = "sudo apt-get --assume-yes install "
APT_UPDATE = "sudo apt update --assume-yes"
existing_sofware = []
installing_list = []
installing_err = []
def is_tool_present(name):
# var = os.system('which vim') will display the output on console and store success value 0 to var
# store the output of which in command line value into the var.
var = os.popen('which ' + name).read()
ret = var.find(name)
return ret != -1
def install_software(software):
#subprocess.call("sudo apt-get update", shell=True)
if is_tool_present(software):
print(software + " is already installed in the system, so not installing \n");
existing_sofware.append(software)
else:
# run the install command in the shell,
ret = subprocess.call(APT_INSTALL_COMMAND + software, shell=True)
# check is the software is installed successfully, if success add in installing_list otherwise add in _err.
if ret == 0:
print "Installed " + software + " Successfully"
installing_list.append(software)
else:
installing_err.append(software)
# Display the table header.
def table_header():
# The value 1,20,25 & 20 are constant based on the column name
print "{:<15} {:<20} {:<25} {:<20}".format('Package', '\"Newly Installed\"', '\"Error while installing\"', '\"Existing package\"')
line = []
for i in range(1, 82):
# creat the list with - for display a line
line.append('-')
# convert the list into a string other wise display as ['-', '-', '-', ...]
str1 = ''.join(str(e) for e in line)
print str1
# To display the row content in the table
def table_row(table_row):
# The value 22, 23,23 & 20 are constant based on the column adjust value row
print "{:<22} {:<23} {:<23} {:<20}".format(table_row[0], table_row[1], table_row[2], table_row[3])
def result_tablular():
# Display the result table header
table_header()
# Display the row value in the tabl
for name in installing_list:
table_row([name, 'Yes', 'NA', 'NA'])
for name in installing_err:
table_row([name, 'NA', 'Yes', 'NA'])
for name in existing_sofware:
table_row([name, 'NA', 'NA', 'Yes'])
def main():
# The follwoing software used for automake
# automake, automake1.11
# libtool --> Used in automake file as libtoolize command
# binutils-dev --> includes header files and static libraries necessary to build programs which use the GNU BFD library
# build-essential --> for libc-devel
software_name = ['vim', 'cscope', 'screen', 'make', 'cmake', 'gdb', 'gcc', 'git', 'automake', 'libtool',
'binutils-dev', 'libc6', 'build-essential']
ret = subprocess.call(APT_UPDATE, shell=True)
# Check and install the list of software available in the software_name
for name in software_name:
install_software(name)
result_tablular()
if __name__ == "__main__":
main()
- Vim
- cscope
- screen
- make
- cmake
- gdb
- gcc
Program:
import subprocess
import shutil
import os
APT_INSTALL_COMMAND = "sudo apt-get --assume-yes install "
APT_UPDATE = "sudo apt update --assume-yes"
existing_sofware = []
installing_list = []
installing_err = []
def is_tool_present(name):
# var = os.system('which vim') will display the output on console and store success value 0 to var
# store the output of which in command line value into the var.
var = os.popen('which ' + name).read()
ret = var.find(name)
return ret != -1
def install_software(software):
#subprocess.call("sudo apt-get update", shell=True)
if is_tool_present(software):
print(software + " is already installed in the system, so not installing \n");
existing_sofware.append(software)
else:
# run the install command in the shell,
ret = subprocess.call(APT_INSTALL_COMMAND + software, shell=True)
# check is the software is installed successfully, if success add in installing_list otherwise add in _err.
if ret == 0:
print "Installed " + software + " Successfully"
installing_list.append(software)
else:
installing_err.append(software)
# Display the table header.
def table_header():
# The value 1,20,25 & 20 are constant based on the column name
print "{:<15} {:<20} {:<25} {:<20}".format('Package', '\"Newly Installed\"', '\"Error while installing\"', '\"Existing package\"')
line = []
for i in range(1, 82):
# creat the list with - for display a line
line.append('-')
# convert the list into a string other wise display as ['-', '-', '-', ...]
str1 = ''.join(str(e) for e in line)
print str1
# To display the row content in the table
def table_row(table_row):
# The value 22, 23,23 & 20 are constant based on the column adjust value row
print "{:<22} {:<23} {:<23} {:<20}".format(table_row[0], table_row[1], table_row[2], table_row[3])
def result_tablular():
# Display the result table header
table_header()
# Display the row value in the tabl
for name in installing_list:
table_row([name, 'Yes', 'NA', 'NA'])
for name in installing_err:
table_row([name, 'NA', 'Yes', 'NA'])
for name in existing_sofware:
table_row([name, 'NA', 'NA', 'Yes'])
def main():
# The follwoing software used for automake
# automake, automake1.11
# libtool --> Used in automake file as libtoolize command
# binutils-dev --> includes header files and static libraries necessary to build programs which use the GNU BFD library
# build-essential --> for libc-devel
software_name = ['vim', 'cscope', 'screen', 'make', 'cmake', 'gdb', 'gcc', 'git', 'automake', 'libtool',
'binutils-dev', 'libc6', 'build-essential']
ret = subprocess.call(APT_UPDATE, shell=True)
# Check and install the list of software available in the software_name
for name in software_name:
install_software(name)
result_tablular()
if __name__ == "__main__":
main()
No comments:
Post a Comment