Syncing /usr/share/ahenk to src and recreating ahenk.install

This commit is contained in:
Tuncay ÇOLAK 2021-01-06 11:01:08 +03:00
parent 9981beee7c
commit f86fd1a891
5 changed files with 42 additions and 20 deletions

View file

@ -429,15 +429,15 @@ class System:
@staticmethod @staticmethod
def total(): def total():
return int(int(psutil.disk_usage('/')[0]) / (1024 * 1024)) return int(int(psutil.disk_usage('/')[0]) / (1000 * 1000))
@staticmethod @staticmethod
def used(): def used():
return int(int(psutil.disk_usage('/')[1]) / (1024 * 1024)) return int(int(psutil.disk_usage('/')[1]) / (1000 * 1000))
@staticmethod @staticmethod
def free(): def free():
return int(int(psutil.disk_usage('/')[2]) / (1024 * 1024)) return int(int(psutil.disk_usage('/')[2]) / (1000 * 1000))
@staticmethod @staticmethod
def percent(): def percent():

View file

@ -32,22 +32,22 @@ class AddNetwork(AbstractPlugin):
try: try:
if self.type == 'STATIC': if self.type == 'STATIC':
if self.is_active is True: if self.is_active is True:
self.content = 'iface {0} inet static\n address {1}\n netmask {2}\n gateway {3}\n'.format(self.name, self.content = 'auto {0}\niface {0} inet static\naddress {1}\nnetmask {2}\ngateway {3}\n'.format(self.name,
self.ip, self.ip,
self.netmask, self.netmask,
self.gateway) self.gateway)
else: else:
self.content = 'iface {0} inet static\n#address {1}\n#netmask {2}\n#gateway {3}\n'.format(self.name, self.content = 'auto {0}\niface {0} inet static\n#address {1}\n#netmask {2}\n#gateway {3}\n'.format(self.name,
self.ip, self.ip,
self.netmask, self.netmask,
self.gateway) self.gateway)
self.logger.debug('Created content for STATIC type.') self.logger.debug('Created content for STATIC type.')
elif self.type == 'DHCP': elif self.type == 'DHCP':
self.content = 'iface {} inet dhcp\n'.format(self.name) self.content = 'auto {0}\niface {0} inet dhcp\n'.format(self.name)
self.logger.debug('Created content for DHCP type.') self.logger.debug('Created content for DHCP type.')
elif self.type == 'LOOPBACK': elif self.type == 'LOOPBACK':
self.content = 'iface {} inet loopback\n'.format(self.name) self.content = 'auto {0}\niface {0} inet loopback\n'.format(self.name)
self.logger.debug('Created content for LOOPBACK type.') self.logger.debug('Created content for LOOPBACK type.')
if self.is_active is False: if self.is_active is False:

View file

@ -42,32 +42,40 @@ class DeleteNetwork(AbstractPlugin):
if not counter: if not counter:
if self.type == 'static': if self.type == 'static':
if self.is_active is True: if self.is_active is True:
self.content = 'iface {0} inet static\n'.format(self.name) self.content = 'auto {0}\n'.format(self.name)
else: else:
self.content = '#iface {0} inet static\n'.format(self.name) self.content = '#auto {0}\n'.format(self.name)
if line.startswith(self.content): if line.startswith(self.content):
counter = 3 counter = 4
else: else:
print(str(line).strip()) print(str(line).strip())
elif self.type == 'dhcp': elif self.type == 'dhcp':
if self.is_active is True: if self.is_active is True:
self.content = 'iface {} inet dhcp\n'.format(self.name) self.content = 'auto {0}\n'.format(self.name)
else: else:
self.content = '#iface {} inet dhcp\n'.format(self.name) self.content = '#auto {0}\n'.format(self.name)
if not line.startswith(self.content): if line.startswith(self.content):
counter = 1
else:
print(str(line).strip()) print(str(line).strip())
# if not line.startswith(self.content):
# print(str(line).strip())
elif self.type == 'loopback': elif self.type == 'loopback':
if self.is_active is True: if self.is_active is True:
self.content = 'iface {} inet loopback\n'.format(self.name) self.content = 'auto {0}\n'.format(self.name)
else: else:
self.content = '#iface {} inet loopback\n'.format(self.name) self.content = 'auto {0}\n'.format(self.name)
if not line.startswith(self.content): if line.startswith(self.content):
counter = 1
else:
print(str(line).strip()) print(str(line).strip())
else: else:
counter -= 1 counter -= 1

View file

@ -22,6 +22,7 @@ class Packages(AbstractPlugin):
cn = '{0}\r\n'.format(self.Ahenk.dn().split(',')[0]) cn = '{0}\r\n'.format(self.Ahenk.dn().split(',')[0])
items = (self.data)['packageInfoList'] items = (self.data)['packageInfoList']
packages = []
for item in items: for item in items:
try: try:
if self.has_attr_json(item, 'tag') and self.has_attr_json(item, 'source'): if self.has_attr_json(item, 'tag') and self.has_attr_json(item, 'source'):
@ -61,6 +62,9 @@ class Packages(AbstractPlugin):
## INSTALL/REMOVE PACKAGE ## INSTALL/REMOVE PACKAGE
p_item = {'packageName': '{0}'.format(item['packageName']),
'tag': '{0}'.format(item['tag'])}
packages.append(p_item)
if item['tag'] == 'Yükle' or item['tag'] == 'Install': if item['tag'] == 'Yükle' or item['tag'] == 'Install':
self.logger.debug( self.logger.debug(
"Installing new package... {0}".format(item['packageName'])) "Installing new package... {0}".format(item['packageName']))
@ -97,18 +101,23 @@ class Packages(AbstractPlugin):
message='{0}\n Paket kaldırılırken ' message='{0}\n Paket kaldırılırken '
'hata oluştu. Hata Mesajı: {1}'.format( 'hata oluştu. Hata Mesajı: {1}'.format(
cn, str(p_err))) cn, str(p_err)))
except Exception as e: except Exception as e:
self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e))) self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e)))
self.delete_source_file()
self.context.create_response(code=self.message_code.TASK_ERROR.value, self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='{0}.\nÖngörülemeyen bir hata oluştu.Hata mesajı:{1}'.format( message='{0}.\nÖngörülemeyen bir hata oluştu.Hata mesajı:{1}'.format(
cn, str(e))) cn, str(e)))
return return
self.delete_source_file()
self.logger.debug('Task handled successfully') self.logger.debug('Task handled successfully')
self.context.create_response(code=self.message_code.TASK_PROCESSED.value, self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='{0} ahenginde, {1} paketi({2}) {3} işlemi başarı ile gerçekleştirildi.'.format(cn,item['packageName'], item['version'], item['tag'])) message='{0} paket kur/kaldır işlemleri başarı ile gerçekleştirildi.'.format(packages))
except Exception as e: except Exception as e:
self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e))) self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e)))
self.delete_source_file()
self.context.create_response(code=self.message_code.TASK_ERROR.value, self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='{0}\nGörev çalıştırılırken beklenmedik bir hata oluştu. Hata Mesajı: {1}'.format( message='{0}\nGörev çalıştırılırken beklenmedik bir hata oluştu. Hata Mesajı: {1}'.format(
cn, cn,
@ -127,6 +136,11 @@ class Packages(AbstractPlugin):
def add_source(self, source): def add_source(self, source):
self.write_file('/etc/apt/sources.list.d/ahenk.list', source+'\n', 'a+') self.write_file('/etc/apt/sources.list.d/ahenk.list', source+'\n', 'a+')
def delete_source_file(self):
if self.is_exist('/etc/apt/sources.list.d/ahenk.list'):
self.delete_file('/etc/apt/sources.list.d/ahenk.list')
self.logger.info("Delete ahenk.list source file")
def handle_task(task, context): def handle_task(task, context):
plugin = Packages(task, context) plugin = Packages(task, context)

View file

@ -89,7 +89,7 @@ class SetupVnc(AbstractPlugin):
# self.execute('su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -o {2}/.vncahenk{3}/vnc.log -display {4}"'.format( # self.execute('su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -o {2}/.vncahenk{3}/vnc.log -display {4}"'.format(
# user_name, self.port, user_name, display_number), result=False) # user_name, self.port, user_name, display_number), result=False)
self.execute( self.execute(
'su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -display {3}"'.format( 'su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -capslock -display {3}"'.format(
user_name, self.port, self.password, display_number), result=False) user_name, self.port, self.password, display_number), result=False)
elif self.data["permission"] == "no": elif self.data["permission"] == "no":
self.logger.info("Lider Ahenk sistem yöneticisi 5 sn sonra bilgisayarınıza uzak erişim sağlayacaktır. ") self.logger.info("Lider Ahenk sistem yöneticisi 5 sn sonra bilgisayarınıza uzak erişim sağlayacaktır. ")
@ -97,10 +97,10 @@ class SetupVnc(AbstractPlugin):
"Lider Ahenk Sistem Yoneticisi tarafindan\n5 sn sonra bilgisayarınıza uzak erişim sağlanacaktır.\nBağlantı kapatıldıktan sonra ayrıca bilgilendirilecektir.", "Lider Ahenk Sistem Yoneticisi tarafindan\n5 sn sonra bilgisayarınıza uzak erişim sağlanacaktır.\nBağlantı kapatıldıktan sonra ayrıca bilgilendirilecektir.",
display_number, user_name, timeout=50000) display_number, user_name, timeout=50000)
time.sleep(2) time.sleep(2)
self.execute('su - {0} -c "x11vnc -gone \'popup\' -rfbport {1} -passwd {2} -display {3}"'.format( self.execute('su - {0} -c "x11vnc -gone \'popup\' -rfbport {1} -passwd {2} -capslock -display {3}"'.format(
user_name, self.port, self.password, display_number), result=False) user_name, self.port, self.password, display_number), result=False)
else: else:
self.execute('su - {0} -c "x11vnc -rfbport {1} -passwd {2} -display {3}"'.format( self.execute('su - {0} -c "x11vnc -rfbport {1} -passwd {2} -capslock -display {3}"'.format(
user_name, self.port, self.password, display_number), result=False) user_name, self.port, self.password, display_number), result=False)
self.logger.info("Lider Ahenk sistem yöneticisi tarafından kullanıcı izni ve bildirim gerektirmeksizin uzak erişim sağlanmıştır") self.logger.info("Lider Ahenk sistem yöneticisi tarafından kullanıcı izni ve bildirim gerektirmeksizin uzak erişim sağlanmıştır")