Little Bug fixings in system.py aand ssh_file_transfer.py, also utility in util.py called install_package

This commit is contained in:
cemrealpsoy 2016-07-20 11:32:50 +03:00
parent c0598f608c
commit cda00f2810
4 changed files with 22 additions and 5 deletions

View file

@ -40,7 +40,6 @@ class Ssh(object):
try: try:
sftp.chdir(self.target_path) # Test if remote_path exists sftp.chdir(self.target_path) # Test if remote_path exists
except IOError: except IOError:
print(self.target_path)
sftp.mkdir(self.target_path) # Create remote_path sftp.mkdir(self.target_path) # Create remote_path
sftp.chdir(self.target_path) sftp.chdir(self.target_path)

View file

@ -41,6 +41,13 @@ class System:
config.read(System.Ahenk.config_path()) config.read(System.Ahenk.config_path())
return config.get('BASE', 'dbPath') return config.get('BASE', 'dbPath')
@staticmethod
def uid():
config = configparser.ConfigParser()
config._interpolation = configparser.ExtendedInterpolation()
config.read(System.Ahenk.config_path())
return config.get('CONNECTION', 'uid')
@staticmethod @staticmethod
def plugins_path(): def plugins_path():
config = configparser.ConfigParser() config = configparser.ConfigParser()
@ -89,7 +96,7 @@ class System:
def received_dir_path(): def received_dir_path():
path = '/tmp/.ahenk/' path = '/tmp/.ahenk/'
if Util.is_exist(path) is False: if Util.is_exist(path) is False:
#TODO write permission add # TODO write permission add
Util.create_directory(path) Util.create_directory(path)
return path return path
@ -330,7 +337,8 @@ class System:
for iface in psutil.net_io_counters(pernic=True): for iface in psutil.net_io_counters(pernic=True):
f = os.popen('ifconfig {} | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'.format(iface)) f = os.popen('ifconfig {} | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'.format(iface))
ip = str(f.read()).replace('\n', '') 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) arr.append(ip)
return arr return arr
@ -355,7 +363,8 @@ class System:
try: try:
addr_list = psutil.net_if_addrs() addr_list = psutil.net_if_addrs()
mac = addr_list[str(iface)][2][1] 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()) arr.append(mac.lower())
except Exception as e: except Exception as e:
pass pass
@ -371,7 +380,8 @@ class System:
arr = [] arr = []
for iface in psutil.net_io_counters(pernic=True): for iface in psutil.net_io_counters(pernic=True):
ip = psutil.net_if_addrs()[str(iface)][0][1] 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) arr.append(ip)
return arr return arr

View file

@ -255,3 +255,10 @@ class Util:
if attr_name in j: if attr_name in j:
return True return True
return False return False
@staticmethod
def install_package(package_name, package_version):
command = "sudo apt-get --yes --force-yes install {0}={1}".format(package_name, package_version)
result_code, p_out, p_err = Util.execute(command)
return result_code, p_out, p_err

View file

@ -0,0 +1 @@
/home/cemre/git/lider-ahenk-package-manager-plugin/ahenk-package-manager/package-manager