merging system.py

This commit is contained in:
Volkan Şahin 2016-07-22 10:43:17 +03:00
commit cbeadd62e1
3 changed files with 38 additions and 7 deletions

View file

@ -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)

View file

@ -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

View file

@ -201,9 +201,25 @@ 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)
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