<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def __write_p4settings(self, config):
 """ write perforce settings """

        self.logger.info("Writing p4settings...")
        root_dir = os.path.expanduser(config.get('root_path'))
        p4settings_path = os.path.join(root_dir, ".p4settings")
        if os.path.exists(p4settings_path):
            if self.target.get('overwrite_p4settings', False):
                self.logger.info("Overwriting existing p4settings...")
                os.remove(p4settings_path)
            else:
                return
        with open(p4settings_path, "w+") as p4settings_file:
            p4settings_file.write(p4settings_template % config.to_dict())
            if config.get('write_password_p4settings', 'no'):
                p4settings_file.write("\nP4PASSWD=%s" % config['password'])