Best Python code snippet using autotest_python
service_helper.py
Source: service_helper.py
...47 group_info = grp.getgrgid(group)48 else:49 group_info = grp.getgrnam(group)50 return group_info[0], group_info[2]51def set_group_user(group=None, user=None):52 """53 Set the group and user id if gid or uid is defined.54 @param group: Change the group id the program is run under55 @param user: Change the user id the program is run under56 """57 if group:58 _, gid = get_group_name_id(group)59 os.setgid(gid)60 os.setegid(gid)61 if user:62 username, uid = get_user_name_id(user)63 # Set environment for programs that use those to find running user64 for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):65 os.environ[name] = username66 os.setuid(uid)67 os.seteuid(uid)68def main():69 parser = optparse.OptionParser()70 parser.allow_interspersed_args = False71 parser.add_option('-l', '--logfile', action='store',72 default=None,73 help='File to redirect stdout to')74 parser.add_option('-c', '--chdir', action='store',75 default=None,76 help='Change to dir before starting the process')77 parser.add_option('-s', '--start-service', action='store_true',78 default=False,79 help='Start service')80 parser.add_option('-k', '--stop-service', action='store_true',81 default=False,82 help='Stop service')83 parser.add_option('-p', '--pidfile', action='store',84 default=None,85 help='Pid file location (Required)')86 parser.add_option('-u', '--chuid', action='store',87 default=None,88 help='UID to run process as')89 parser.add_option('-g', '--chgid', action='store',90 default=None,91 help='GID to run process as')92 options, args = parser.parse_args()93 if not options.pidfile:94 print 'A pidfile must always be supplied'95 parser.print_help()96 sys.exit(1)97 set_group_user(group=options.chgid, user=options.chuid)98 if options.start_service:99 start_service(args, options.pidfile, options.logfile, options.chdir)100 elif options.stop_service:101 stop_service(options.pidfile)102 else:103 print 'Nothing to do, you must specify to start or stop a service'104 parser.print_help()105if __name__ == '__main__':...
Check out the latest blogs from LambdaTest on this topic:
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
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!!