def parse_status( self ):
        if self.path == '':
            print 'path not set'
            return
        os.chdir( self.path )
        rc, report = commands.getstatusoutput('git status')
        self.raw_status = report
        if rc != 0:
            return

        if report.find('Not a git repository') != -1:
            self.isrepo = 0
        else:
            self.isrepo = 1
        if report.find('branch') != -1:
            reout = re.search(r'branch (.*)',report)
            if reout:
                self.branch = reout.group(1)

        if report.find('working directory clean') != -1:
            self.wdc = 0
        else :
            if report.find('Untracked files:') != -1:
                # if this is not an initial commit following should return something
                reout = re.split( '(nothing added to commit but untracked files present).*', report, re.M)
                ufiles = reout[0]
                reout = re.split( '(no changes added to commit).*', ufiles, re.M)
                ufiles = reout[0]
                # get to te relevant section
                reout = re.split( '(Untracked files:).*', ufiles, re.M)
                ufiles = reout[2]
                reout = re.split( '(what will be committed\)).*', ufiles, re.M)
                ufiles = re.sub(r'\x1b[^m]*m','',reout[2])
                ufiles = re.split( '\n', ufiles )
                ufiles = filter( None, ufiles )
                self.ufiles = [ f.replace('\t', '') for f in ufiles]

            if report.find('Changes not staged for commit:') != -1:
                # if this is not an initial commit following should return something
                reout = re.split( '(nothing added to commit but untracked files present).*', report, re.M)
                cfiles = reout[0]
                reout = re.split( '(no changes added to commit).*', cfiles, re.M)
                cfiles = reout[0]
                reout = re.split( '(Untracked files:).*', cfiles, re.M)
                cfiles = reout[0]
                # get to te relevant section
                reout = re.split( '(Changes not staged for commit:).*', cfiles, re.M)
                cfiles = reout[2]
                reout = re.split( '(discard changes in working directory\)).*', cfiles, re.M)
                cfiles = re.sub(r'\x1b[^m]*m','',reout[2])
                cfiles = re.split( '\n', cfiles )
                cfiles = filter( None, cfiles )
                cfiles = [ f.replace('\t', '') for f in cfiles]
                self.cfiles = [ f.replace('modified:', '').strip() for f in cfiles]

            if report.find('Changes to be committed:') != -1:
                # if this is not an initial commit following should return something
                reout = re.split( '(nothing added to commit but untracked files present).*', report, re.M)
                sfiles = reout[0]
                reout = re.split( '(no changes added to commit).*', sfiles, re.M)
                sfiles = reout[0]
                reout = re.split( '(Untracked files:).*', sfiles, re.M)
                sfiles = reout[0]
                reout = re.split( '(Unmerged paths:).*', report, re.M)
                sfiles = reout[0]
                reout = re.split( '(Changes not staged for commit:).*', sfiles, re.M)
                sfiles = reout[0]
                # get to te relevant section
                reout = re.split( '(Changes to be committed:).*', sfiles, re.M)
                sfiles = reout[2]
                if sfiles.find( '..." to unstage\)' ) != -1:
                    reout = re.split( '(..." to unstage\)).*', sfiles, re.M)
                    sfiles = reout[2]

                sfiles = re.sub(r'\x1b[^m]*m','',reout[2])
                sfiles = re.split( '\n', sfiles )
                sfiles = filter( None, sfiles )
                sfiles = [ f.replace('\t', '') for f in sfiles]
                sfiles = [ f.replace('new file:', '').strip() for f in sfiles]
                self.sfiles = [ f.replace('modified:', '').strip() for f in sfiles]

            if report.find('Unmerged paths:') != -1:
                # if this is not an initial commit following should return something
                reout = re.split( '(nothing added to commit but untracked files present).*', report, re.M)
                sfiles = reout[0]
                reout = re.split( '(no changes added to commit).*', sfiles, re.M)
                sfiles = reout[0]
                reout = re.split( '(Untracked files:).*', sfiles, re.M)
                sfiles = reout[0]
                reout = re.split( '(Changes not staged for commit:).*', sfiles, re.M)
                sfiles = reout[0]
                reout = re.split( '(Unmerged paths:).*', sfiles, re.M)
                sfiles = reout[0]
                # get to te relevant section
                reout = re.split( '(Changes to be committed:).*', sfiles, re.M)
                sfiles = reout[2]
                if sfiles.find( '..." to unstage\)' ) != -1:
                    reout = re.split( '(..." to unstage\)).*', sfiles, re.M)
                    sfiles = reout[2]

                sfiles = re.sub(r'\x1b[^m]*m','',reout[2])
                sfiles = re.split( '\n', sfiles )
                sfiles = filter( None, sfiles )
                sfiles = [ f.replace('\t', '') for f in sfiles]
                sfiles = [ f.replace('new file:', '').strip() for f in sfiles]
                sfiles = [ f.replace('modified:', '').strip() for f in sfiles]
                sfiles = [ f.replace('both modified:', '').strip() for f in sfiles]
                self.sfiles += sfiles

        if len( self.sfiles ) + len( self.cfiles ) != 0 :
            self.commit = 1
        else :
            self.commit = 0
dataset/ETHPy150Open etola/git-manager/git_report_structure.py/GitReport.parse_status/original