Best Python code snippet using lisa_python
lso-gui-new.py
Source:lso-gui-new.py
...168169 self.window.destroy()170 self.reboot()171172 def delete_swap(self):173 if not swap_handler.has_swap():174 if self.db.language == "en":175 msg_box.showerror(176 title='Error', message='Swap area already doesn\'t exist!.')177 else:178 msg_box.showerror(179 title='Hata', message='Swap alanı zaten bulunmuyor!')180 return None181182 if swap_handler.delete_swap() == 'ERROR':183 if self.db.language == "en":184 msg_box.showerror(185 title='Error', message='There was an error while deleting swap are.')186 else:187 msg_box.showerror(188 title='Hata', message='Swap alanı silinirken bir hata oluÅtu.')189 else:190 if self.db.language == "en":191 msg_box.showinfo(192 title='Error', message='Succesfully deleted swap area.')193 self.situation_info.config(text='Situation: no swap area')194 else:195 msg_box.showinfo(196 title='Hata', message='Swap alanı baÅarıyla silindi!')
...
lso.py
Source:lso.py
...17# * function to delelete swap18192021def delete_swap():22 satir = 023 try:24 os.system("sudo swapoff -v /swapfile")25 os.system("sudo rm /swapfile")2627 def sil(satir):28 f.seek(0)29 satirlar = f.readlines()30 satirlar.pop(satir)31 print(satirlar)32 os.remove("/etc/fstab")33 nf = open("/etc/fstab","w")34 for line2 in satirlar:35 nf.write(line2)363738 with open("/etc/fstab") as f:39 for line in f.readlines():40 satir+=141 if("swap" in line):42 sil(satir - 1)4344 except Exception as e:45 if language == '1':46 print('There was an error while deleting the swap.')47 print('Error description:', e)48 else:49 print('Swap silinirken bir hata çıktı.')50 print('Hata açıklaması:', e)5152 if language == "1":53 print('Swap deleted succesfully!')54 else:55 print('Swap silindi!')5657# * function to add swap585960def add_swap(size):61 try:62 os.system("sudo fallocate -l {}M /swapfile".format(size))63 os.system("sudo chmod 600 /swapfile")64 os.system("sudo mkswap /swapfile")65 os.system("sudo swapon /swapfile")6667 with open("/etc/fstab", "a") as writer:68 writer.write("/swapfile none swap defaults 0 0")69 except Exception as e:70 if language == '1':71 print('There was an error while deleting the swap.')72 print('Error description:', e)73 else:74 print('Swap silinirken bir hata çıktı.')75 print('Hata açıklaması:', e)7677 if language == "1":78 print('Swap added succesfully.')79 else:80 print("Swap alanı baÅarıyla eklendi!")818283print("Swap Area Transactions\n")84print('Swap Alanı Kontrolcüsü')85print("Choose a language/Bir dil seçiniz.\n")8687language = input("1-Türkçe/2-English\n")8889if (language == "1"):9091 print("Hangi iÅlemi yapmak istiyorsunuz?\n")9293 process = input("1-Swap alanı oluÅturma/2-Swap alanı silme\n")94 if (process == "1"):95 if has_swap():96 print("Swap alanı zaten mevcut!")97 sys.exit()9899 size = int(100 input("Kaç GB alan ayırmak istiyorsunuz? (1-2 GB Åeklinde...)")) * 1024101 print('Ayırılacak alan:', size, type(size))102103 print("Ä°Ålemler baÅlıyor..\n")104 time.sleep(3)105 add_swap(size)106107 do_reboot = input("Sistem yeninden baÅlatılsın mı? e/h\n")108 if (do_reboot == "e"):109 os.system("reboot")110 else:111 sys.exit()112113 if (process == "2"):114 do_continue = input(115 "Bu iÅlem, Swap alanı sonradan oluÅturulmamıŠise hatalarla sonuçlanabilir, devam etmek istiyor musunuz? e/h")116117 if (do_continue == "e"):118 print("Ä°Ålemler baÅlıyor..")119 time.sleep(3)120121 if not has_swap():122 print("Swap alanı zaten mevcut deÄil!")123 sys.exit()124125 delete_swap()126127if (language == "2"):128 print("What action do you want to take?\n")129130 process = input("1-Creating a swap area/2-Deleting a swap area\n")131 if (process == "1"):132 if has_swap():133 print("Swap space already exists!")134 sys.exit()135136 size = int(input(137 "How many GB of space do you want to allocate? (in the form of 1-2 GB...)")) * 1024138 print('Size to allocate (mb):', size, type(size))139 print("Process is starting...\n")140 time.sleep(3)141142 add_swap(size)143144 end = input("Reboot the system? y/n\n")145 if (end == "y"):146 os.system("reboot")147 else:148 sys.exit()149150 if (process == "2"):151 do_continue = input(152 "This operation may cause minor errors if the swap space is not created afterwards, do you want to continue? y/n")153154 if (do_continue == "e"):155 print("Operations begin..")156 time.sleep(3)157158 if not has_swap():159 print("Swap space already does not exist!")160 sys.exit()161
...
swapfoo.py
Source:swapfoo.py
...78new_swap = _swapfoo.new_swap79def copy_swap(value):80 return _swapfoo.copy_swap(value)81copy_swap = _swapfoo.copy_swap82def delete_swap(obj):83 return _swapfoo.delete_swap(obj)84delete_swap = _swapfoo.delete_swap85def swap_assign(obj, value):86 return _swapfoo.swap_assign(obj, value)87swap_assign = _swapfoo.swap_assign88def swap_value(obj):89 return _swapfoo.swap_value(obj)90swap_value = _swapfoo.swap_value91def fact(n):92 return _swapfoo.fact(n)93fact = _swapfoo.fact94def swap(S):95 return _swapfoo.swap(S)96swap = _swapfoo.swap97# This file is compatible with both classic and new-style classes.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!