def scan()

in src/plugins/scanners/git-sloc.py [0:0]


def scan(KibbleBit, source):
    
    rid = source['sourceID']
    url = source['sourceURL']
    rootpath = "%s/%s/git" % (KibbleBit.config['scanner']['scratchdir'], source['organisation'])
    gpath = os.path.join(rootpath, rid)
    
    if source['steps']['sync']['good'] and os.path.exists(gpath):
        source['steps']['count'] = {
                'time': time.time(),
                'status': 'SLoC count started at ' + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()),
                'running': True,
                'good': True,
            }
        KibbleBit.updateSource(source)
        
        try:
            branch = plugins.utils.git.defaultBranch(source, gpath)
            subprocess.call('cd %s && git checkout %s' % (gpath, branch), shell = True)
        except:
            KibbleBit.pprint("SLoC counter failed to find main branch for %s!!" % url)
            return False
        
        KibbleBit.pprint("Running SLoC count for %s" % url)
        languages, codecount, comment, blank, years, cost = plugins.utils.sloc.count(gpath)
        
        sloc = {
            'sourceID': source['sourceID'],
            'loc': codecount,
            'comments': comment,
            'blanks': blank,
            'years': years,
            'cost': cost,
            'languages': languages
        }
        source['sloc'] = sloc
        source['steps']['count'] = {
            'time': time.time(),
            'status': 'SLoC count completed at ' + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()),
            'running': False,
            'good': True,
        }
        KibbleBit.updateSource(source)