def clone_data(self, data_path):
self.data_path = data_path<EOL>data_url = urlparse.urlparse(self.data_path)<EOL>if data_url.scheme in SCHEMES or (data_url.scheme == '<STR_LIT>' and '<STR_LIT::>' in data_url.path):<EOL><INDENT>data_name = os.path.splitext(os.path.basename(data_url.path))[<NUM_LIT:0>]<EOL>data_destination = os.path.join(self.clone_dir, data_name)<EOL>clone_data = True<EOL>if os.path.isdir(data_destination):<EOL><INDENT>self.logger.info('<STR_LIT>')<EOL>with Dir(data_destination):<EOL><INDENT>rc, out, err = self.cmd.gather("<STR_LIT>")<EOL>if rc:<EOL><INDENT>raise GitDataException('<STR_LIT>'.format(err))<EOL><DEDENT>lines = out.strip().split('<STR_LIT:\n>')<EOL>synced = ('<STR_LIT>' not in lines[<NUM_LIT:0>] and '<STR_LIT>' not in lines[<NUM_LIT:0>] and len(lines) == <NUM_LIT:1>)<EOL>rc, out, err = self.cmd.gather("<STR_LIT>")<EOL>if rc:<EOL><INDENT>raise GitDataException('<STR_LIT>'.format(err))<EOL><DEDENT>branch = out.strip()<EOL>if branch != self.branch:<EOL><INDENT>if not synced:<EOL><INDENT>msg = ('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>).format(branch, self.branch)<EOL>raise GitDataBranchException(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rc, out, err = self.cmd.gather(["<STR_LIT>", "<STR_LIT>", self.data_path, self.branch])<EOL>if rc:<EOL><INDENT>raise GitDataException('<STR_LIT>'.format(err))<EOL><DEDENT>remote = out.strip().split('<STR_LIT:\t>')[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>self.cmd.check_assert('<STR_LIT>'.format(remote))<EOL>self.logger.info('<STR_LIT>'.format(self.data_path))<EOL>clone_data = False<EOL><DEDENT>except:<EOL><INDENT>if not synced:<EOL><INDENT>msg = ('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>).format(data_destination)<EOL>raise GitDataException(msg)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if clone_data:<EOL><INDENT>if os.path.isdir(data_destination):  <EOL><INDENT>shutil.rmtree(data_destination)<EOL><DEDENT>self.logger.info('<STR_LIT>'.format(self.data_path))<EOL>if not os.path.isdir(data_destination):<EOL><INDENT>cmd = "<STR_LIT>".format(self.branch, self.data_path, data_destination)<EOL>rc, out, err = self.cmd.gather(cmd)<EOL>if rc:<EOL><INDENT>raise GitDataException('<STR_LIT>'.format(err))<EOL><DEDENT><DEDENT><DEDENT>self.remote_path = self.data_path<EOL>self.data_path = data_destination<EOL><DEDENT>elif data_url.scheme in ['<STR_LIT>', '<STR_LIT:file>']:<EOL><INDENT>self.remote_path = None<EOL>self.data_path = os.path.abspath(self.data_path)  <EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>.format(self.data_path, data_url.scheme)<EOL>)<EOL><DEDENT>if self.sub_dir:<EOL><INDENT>self.data_dir = os.path.join(self.data_path, self.sub_dir)<EOL><DEDENT>else:<EOL><INDENT>self.data_dir = self.data_path<EOL><DEDENT>if not os.path.isdir(self.data_dir):<EOL><INDENT>raise GitDataPathException('<STR_LIT>'.format(self.sub_dir))<EOL><DEDENT>
Clones data for given data_path:
:param str data_path: Git url (git/http/https) or local directory path