Best Python code snippet using avocado_python
automazione_tende.py
Source:automazione_tende.py  
...91        if not self.curtain_east.motor.is_active:92            if steps["east"] is self.n_step_corsa:93                self.curtain_east.open_up()94            elif steps["east"] == 0:95                self.curtain_east.bring_down()96            else:97                self.curtain_east.move(steps["east"])98        if not self.curtain_west.motor.is_active:99            if steps["west"] is self.n_step_corsa:100                self.curtain_west.open_up()101            elif steps["west"] == 0:102                self.curtain_west.bring_down()103            else:104                self.curtain_west.move(steps["west"])105    def calculate_curtains_steps(self):106        """107            Change the height of the curtains108            to based on the given Coordinates109        """110        telescope = self.telescope111        steps = {}112        Logger.getLogger().debug("Telescope status %s", telescope.status)113        # TODO verify tele height:114        # if less than east_min_height e ovest_min_height115        if telescope.status is TelescopeStatus.LOST or telescope.status is TelescopeStatus.ERROR:116            steps["west"] = self.curtain_west.steps()117            steps["east"] = self.curtain_east.steps()118        if telescope.is_below_curtains_area():119            #   keep both curtains to 0120            steps["west"] = 0121            steps["east"] = 0122            #   else if higher to east_max_height e ovest_max_height123        elif telescope.is_above_curtains_area(self.alt_max_tend_e, self.alt_max_tend_w) or not telescope.is_within_curtains_area():124            #   move both curtains max open125            steps["west"] = self.n_step_corsa126            steps["east"] = self.n_step_corsa127            #   else if higher to ovest_min_height and Az tele to west128        elif telescope.status == TelescopeStatus.WEST:129            Logger.getLogger().debug("inside west status")130            #   move curtain east max open131            steps["east"] = self.n_step_corsa132            #   move curtain west to f(Alt telescope - x)133            steps["west"] = round((telescope.coords["alt"]-self.alt_min_tend_w)/self.increm_w)134            #   else if higher to ovest_min_height and Az tele to est135        elif telescope.status == TelescopeStatus.EAST:136            Logger.getLogger().debug("inside east status")137            #   move curtian west max open138            steps["west"] = self.n_step_corsa139            #   if inferior to est_min_height140            #   move curtain east to f(Alt tele - x)141            steps["east"] = round((telescope.coords["alt"]-self.alt_min_tend_e)/self.increm_e)142        Logger.getLogger().debug("calculatd curtain steps %s", steps)143        return steps144    def park_curtains(self) -> None:145        """" Bring down both curtains """146        self.curtain_east.bring_down()147        self.curtain_west.bring_down()148        self.crac_status.curtain_east_status = self.curtain_east.read()149        self.crac_status.curtain_east_steps = self.curtain_east.steps()150        self.crac_status.curtain_west_status = self.curtain_west.read()151        self.crac_status.curtain_west_steps = self.curtain_west.steps()152    def motor_stop(self):153        """ Disable motor control """154        self.curtain_east.motor_stop()155        self.curtain_west.motor_stop()156    def is_diff_steps(self, cs: Dict[str, int], ps: Dict[str, int]) -> bool:157        minDiffSteps = Config.getInt("diff_steps", "encoder_step")158        is_east = abs(cs["east"] - ps["east"]) > minDiffSteps159        is_west = abs(cs["west"] - ps["west"]) > minDiffSteps160        return is_east or is_west161    def open_roof(self):162        """ Open the roof and update the roof status in CracStatus object """163        status_roof = self.roof_control.read()164        Logger.getLogger().info("Lo status tetto iniziale: %s ", str(status_roof))165        if status_roof != Status.OPEN:166            self.roof_control.open()167            status_roof = self.roof_control.read()168        Logger.getLogger().debug("Stato tetto finale: %s", str(status_roof))169        self.crac_status.roof_status = status_roof170    def close_roof(self) -> None:171        """ Close the roof and update the roof status in CracStatus object """172        status_roof = self.roof_control.read()173        Logger.getLogger().debug("Stato tetto iniziale: %s", str(status_roof))174        if status_roof != Status.CLOSED:175            self.roof_control.close()176            status_roof = self.roof_control.read()177        Logger.getLogger().debug("Stato tetto finale: %s", str(status_roof))178        self.crac_status.roof_status = status_roof179    def power_on_tele(self):180        """ turn on the power switch and update its status in CracStatus object """181        self.power_tele_control.on()182        self.telescope.sync_time = datetime.datetime.utcnow()183        Logger.getLogger().debug("UTC time di conversione coord per sincronizzazione telescopio %s:", self.telescope.sync_time)184    def power_off_tele(self):185        """ turn off power switch and update its status in CracStatus object """186        self.telescope.nosync()187        self.power_tele_control.off()188    def power_on_ccd(self):189        """ turn on ccd and update its status in CracStatus object """190        self.power_ccd_control.on()191    def power_off_ccd(self):192        """ turn off ccd and update its status in CracStatus object """193        self.power_ccd_control.off()194    def panel_on(self):195        """ turn on panel flat and update its status in CracStatus object """196        self.panel_control.on()197        self.telescope.move_tele(tr=1)198    def panel_off(self):199        """ turn off panel flat and update its status in CracStatus object """200        self.panel_control.off()201    # SYNC SWITCH202    def time_sync(self):203        if self.power_tele_control.read() is ButtonStatus.OFF:204            self.power_on_tele()205        self.telescope.sync()206    def light_on(self):207        """ turn on light on dome and update its status in CracStatus object """208        self.light_control.on()209    def light_off(self):210        """ turn off light on dome and update its status in CracStatus object """211        self.light_control.off()212    def exit_program(self, n: int = 0) -> None:213        """ Shutdown the server """214        Logger.getLogger().info("Uscita dall'applicazione con codice %s", n)215        self.telescope.close_connection()216        self.curtain_east.bring_down()217        self.curtain_west.bring_down()218        self.curtain_east.curtain_closed.wait_for_active()219        self.curtain_west.curtain_closed.wait_for_active()220        self.roof_control.close()221    def exec(self) -> None:222        """ Move the curtains and update the telescope coordinates"""223        steps = self.calculate_curtains_steps()224        Logger.getLogger().debug("calculated steps %s", steps)225        self.crac_status.curtain_east_status = self.curtain_east.read()226        self.crac_status.curtain_east_steps = self.curtain_east.steps()227        self.crac_status.curtain_west_status = self.curtain_west.read()228        self.crac_status.curtain_west_steps = self.curtain_west.steps()229        Logger.getLogger().debug("curtain_east_steps %s", self.curtain_east.steps())230        Logger.getLogger().debug("curtain_east_status %s", self.curtain_east.read())231        Logger.getLogger().debug("curtain_west_steps %s", self.curtain_west.steps())...ball.py
Source:ball.py  
...88                self.set_xspeed(0)89            if paddle.move_ball == 0 and self.__type != "shooting":90                for i in range(0 , len(brick_level_1)):91                    brick_level_1[i].clear_brick(grid)92                    brick_level_1[i].bring_down()93                94                for i in range(0 , len(brick_level_2)):95                    brick_level_2[i].clear_brick(grid)96                    brick_level_2[i].bring_down()97                for i in range(0 , len(brick_level_3)):98                    brick_level_3[i].clear_brick(grid)99                    brick_level_3[i].bring_down()100                for i in range(0 , len(brick_level_4)):101                    brick_level_4[i].clear_brick(grid)102                    brick_level_4[i].bring_down()103                104        new_y = self.get_y() + self.get_yspeed()105        new_x = self.get_x() + self.get_xspeed()106        if new_y <= 0:107            self.set_yspeed(-1*self.get_yspeed())108        elif new_y >= HEIGHT-PADDLE_POS_Y and paddle.get_x() <= self.get_x() and paddle.get_x() + paddle.get_length() >= self.get_x() and self.__type == "boss":109            paddle.clear_paddle(grid)             110            paddle.set_x(PADDLE_POS_X)             111            paddle.set_y(PADDLE_POS_Y)112            grid[self.get_y()][self.get_x()] = ' '113            paddle.move_paddle(0 , grid , ball)114            player.set_lives(player.get_lives() - 1)115            for i in powerups[:]:116                if i.get_type() == "expand_paddle":...mac_changer.py
Source:mac_changer.py  
1#mac changer2#changes interface MAC address to any specified3#github.com/the-jcksn4import subprocess5import os6import argparse7import re8def cmdline(command):9	terminal_output = subprocess.getoutput(command)10	return(terminal_output)11def getcurrentmac():12	current_mac = cmdline('ifconfig')13	current_mac = str(current_mac.split(args.interface))14	current_mac = current_mac.split('\\n')15	for line in current_mac:16	        if 'ether' in line:17               	 mac_address = line.split(' ')18               	 for segment in mac_address:19        	                if ':' in segment:20	                                initial_mac = segment21	return(initial_mac)22parser = argparse.ArgumentParser()23parser.add_argument('-i', default='none', dest='interface', help='Provide an interface to change MAC on. <REQUIRED>', type=str)24parser.add_argument('-m', default='none', dest='new_mac', help='Provide the desired MAC address', type=str)25args = parser.parse_args()26if not 'SUDO_UID' in os.environ.keys():27	print('\nThis script requires super user privs (sudo), please come back when the grown-ups say it\'s ok...')28	quit()29if args.interface == 'none':30	print('\nNo interface specified with \'-i\'')31	print('Quitting...')32	quit()33if args.new_mac == 'none':34	print('\nNo desired MAC address specified with \'-m\'')35	print('Quitting...')36	quit()37if not re.match("[0-9a-f]{2}([:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", args.new_mac):38	print('\nInvalid MAC address supplied.')39	print('Please use the format 12:23:ab:cd:45:67')40	quit()41current_mac = cmdline('ifconfig')42current_mac = str(current_mac.split(args.interface))43current_mac = current_mac.split('\\n')44macadd = getcurrentmac()45print('\nCurrent MAC address is  : ',macadd)46print('Changing MAC address to : ',args.new_mac)47bring_down = 'sudo ifconfig ' + args.interface + ' down'48bring_up = 'sudo ifconfig ' + args.interface + ' up'49change_mac = 'sudo ifconfig ' + args.interface + ' hw ether ' + args.new_mac50cmdline(bring_down)51cmdline(change_mac)52cmdline(bring_up)53macadd = getcurrentmac()54if macadd == args.new_mac:55	print('\nChange was successful.')56else:...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!!
