mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-14 07:22:18 +03:00
merging system.py
This commit is contained in:
commit
cbeadd62e1
3 changed files with 38 additions and 7 deletions
|
@ -42,7 +42,6 @@ class Ssh(object):
|
|||
try:
|
||||
sftp.chdir(self.target_path) # Test if remote_path exists
|
||||
except IOError:
|
||||
print(self.target_path)
|
||||
sftp.mkdir(self.target_path) # Create remote_path
|
||||
sftp.chdir(self.target_path)
|
||||
|
||||
|
|
|
@ -62,6 +62,13 @@ class System:
|
|||
config.read(System.Ahenk.config_path())
|
||||
return config.get('SESSION', 'get_policy_timeout')
|
||||
|
||||
@staticmethod
|
||||
def uid():
|
||||
config = configparser.ConfigParser()
|
||||
config._interpolation = configparser.ExtendedInterpolation()
|
||||
config.read(System.Ahenk.config_path())
|
||||
return config.get('CONNECTION', 'uid')
|
||||
|
||||
@staticmethod
|
||||
def plugins_path():
|
||||
config = configparser.ConfigParser()
|
||||
|
@ -351,7 +358,8 @@ class System:
|
|||
for iface in psutil.net_io_counters(pernic=True):
|
||||
f = os.popen('ifconfig {} | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'.format(iface))
|
||||
ip = str(f.read()).replace('\n', '')
|
||||
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$', ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':
|
||||
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$',
|
||||
ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':
|
||||
arr.append(ip)
|
||||
return arr
|
||||
|
||||
|
@ -376,7 +384,8 @@ class System:
|
|||
try:
|
||||
addr_list = psutil.net_if_addrs()
|
||||
mac = addr_list[str(iface)][2][1]
|
||||
if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower()) and str(mac) != '00:00:00:00:00:00':
|
||||
if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower()) and str(
|
||||
mac) != '00:00:00:00:00:00':
|
||||
arr.append(mac.lower())
|
||||
except Exception as e:
|
||||
pass
|
||||
|
@ -392,7 +401,8 @@ class System:
|
|||
arr = []
|
||||
for iface in psutil.net_io_counters(pernic=True):
|
||||
ip = psutil.net_if_addrs()[str(iface)][0][1]
|
||||
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$', ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':
|
||||
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$', ip) and str(
|
||||
ip) != 'localhost' and str(ip) != '127.0.0.1':
|
||||
arr.append(ip)
|
||||
return arr
|
||||
|
||||
|
|
|
@ -201,10 +201,26 @@ class Util:
|
|||
raise
|
||||
|
||||
@staticmethod
|
||||
def install_with_apt_get(package_name):
|
||||
def install_with_apt_get(package_name, package_version=None):
|
||||
try:
|
||||
process = subprocess.Popen('apt-get install --yes --force-yes ' + package_name, shell=True)
|
||||
process.wait()
|
||||
if package_version is not None:
|
||||
process = subprocess.Popen('apt-get install --yes --force-yes {0}={1}'.format(package_name, package_version), shell=True)
|
||||
process.wait()
|
||||
else:
|
||||
process = subprocess.Popen('apt-get install --yes --force-yes {0}'.format(package_name), shell=True)
|
||||
process.wait()
|
||||
except:
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
def uninstall_package(package_name, package_version=None):
|
||||
try:
|
||||
if package_version is not None:
|
||||
process = subprocess.Popen('apt-get purge --yes --force-yes {0}={1}'.format(package_name, package_version), shell=True)
|
||||
process.wait()
|
||||
else:
|
||||
process = subprocess.Popen('apt-get purge --yes --force-yes {0}'.format(package_name), shell=True)
|
||||
process.wait()
|
||||
except:
|
||||
raise
|
||||
|
||||
|
@ -255,3 +271,9 @@ class Util:
|
|||
if attr_name in j:
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def remove_package(package_name, package_version):
|
||||
command = "sudo apt-get --yes --force-yes purge {0}={1}".format(package_name, package_version)
|
||||
result_code, p_out, p_err = Util.execute(command)
|
||||
return result_code, p_out, p_err
|
||||
|
|
Loading…
Reference in a new issue