def generateforall(target_repo, user_email): cloning_repo = '[email protected]:' + target_repo tar = cloning_repo.split('/')[-2].split(':')[1] cloning_repo = cloning_repo.replace(tar, ToolUser) user = user_email ontologies = get_ontologies_in_online_repo(target_repo) changed_files = ontologies print 'current file dir: %s' % str( os.path.dirname(os.path.realpath(__file__))) # comm = "python /home/ubuntu/OnToology/OnToology/autoncore.py " #comm = "python %s " % \ # str((os.path.join(os.path.dirname(os.path.realpath(__file__)), 'autoncore.py'))) if 'virtual_env_dir' in os.environ: print 'virtual_env_dir is in environ' comm = "%s %s " % \ (os.path.join(os.environ['virtual_env_dir'], 'bin', 'python'), (os.path.join(os.path.dirname(os.path.realpath(__file__)), 'autoncore.py'))) else: print 'virtual_env_dir is NOT in environ' comm = "python %s " % \ (os.path.join(os.path.dirname(os.path.realpath(__file__)), 'autoncore.py')) comm += ' "' + target_repo + '" "' + user + '" ' for c in changed_files: comm += '"' + c.strip() + '" ' if settings.test_conf['local']: print "running autoncode in the same thread" git_magic(target_repo, user, changed_files) else: print 'running autoncore code as: ' + comm try: subprocess.Popen(comm, shell=True) except Exception as e: sys.stdout.flush() sys.stderr.flush() error_msg = str(e) print 'error running generall all subprocess: ' + error_msg if 'execv() arg 2 must contain only strings' in error_msg: return { 'status': False, 'error': 'make sure that your repository filenames does not have accents or special characters' } else: return { 'status': False, 'error': 'generic error, please report the problem to us at [email protected]' } sys.stdout.flush() sys.stderr.flush() return {'status': True}
def get_stats(): stats = { 'mean': 0, 'median': 0, 'num_of_ontologies': 0, 'num_of_repos': 0, 'num_of_pub': 0, 'num_of_reg_users': 0, 'onto_per_repo': { 'data': [], 'labels': [] } } repos = Repo.objects.all() ontologies_per_repo = [] num_corr_repos = 0 # number of repos that has at least one ontology for r in repos: if '/Curso2017-2018' not in r.url: ontos = get_ontologies_in_online_repo(r.url) if ontos != []: num_of_ontos = len(ontos) ontologies_per_repo.append(num_of_ontos) num_corr_repos += 1 if num_of_ontos > 99: msg = "large repo: " + r.url print(msg) llog(msg) num_of_ontologies = sum(ontologies_per_repo) stats['mean'] = num_of_ontologies / num_corr_repos if num_corr_repos > 0: ontologies_per_repo = sorted(ontologies_per_repo) if num_corr_repos % 2 == 0: # even idx = (num_corr_repos - 1) / 2 print("original idx: ") print(idx) idx = int(idx) print("int idx: %d" % idx) stats['median'] = (ontologies_per_repo[idx] + ontologies_per_repo[idx + 1]) / 2 else: idx = num_corr_repos / 2 stats['median'] = ontologies_per_repo[idx] stats['num_of_ontologies'] = num_of_ontologies stats['num_of_repos'] = len(repos) stats['num_of_pub'] = len(PublishName.objects.all()) stats['num_of_reg_users'] = len(OUser.objects.all()) c = Counter(ontologies_per_repo) for k in sorted(c.keys()): stats['onto_per_repo']['data'].append(c[k]) stats['onto_per_repo']['labels'].append(k) return stats
def generateforall(target_repo, user_email): cloning_repo = '[email protected]:' + target_repo tar = cloning_repo.split('/')[-2].split(':')[1] cloning_repo = cloning_repo.replace(tar, ToolUser) user = user_email ontologies = get_ontologies_in_online_repo(target_repo) changed_files = ontologies comm = "python /home/ubuntu/OnToology/OnToology/autoncore.py " comm += ' "' + target_repo + '" "' + user + '" "' + cloning_repo + '" ' for c in changed_files: comm += '"' + c.strip() + '" ' if settings.TEST: print 'will call git_magic with target=%s, user=%s, cloning_repo=%s, changed_files=%s' % \ (target_repo, user, cloning_repo, str(changed_files)) git_magic(target_repo, user, cloning_repo, changed_files) else: print 'running autoncore code as: ' + comm subprocess.Popen(comm, shell=True)
def generateforall(target_repo, user_email): cloning_repo = '[email protected]:' + target_repo tar = cloning_repo.split('/')[-2].split(':')[1] cloning_repo = cloning_repo.replace(tar, ToolUser) user = user_email ontologies = get_ontologies_in_online_repo(target_repo) changed_files = ontologies comm = "python /home/ubuntu/OnToology/OnToology/autoncore.py " comm += ' "' + target_repo + '" "' + user + '" "' + cloning_repo + '" ' for c in changed_files: comm += '"' + c.strip() + '" ' if settings.TEST: print 'will call git_magic with target=%s, user=%s, cloning_repo=%s, changed_files=%s' % \ (target_repo, user, cloning_repo, str(changed_files)) git_magic(target_repo, user, cloning_repo, changed_files) else: print 'running autoncore code as: ' + comm subprocess.Popen(comm, shell=True)
def generateforall(target_repo, user_email): user = user_email ontologies = get_ontologies_in_online_repo(target_repo) changed_files = ontologies print 'current file dir: %s' % str( os.path.dirname(os.path.realpath(__file__))) if 'virtual_env_dir' in os.environ: print 'virtual_env_dir is in environ' comm = "%s %s " % \ (os.path.join(os.environ['virtual_env_dir'], 'bin', 'python'), (os.path.join(os.path.dirname(os.path.realpath(__file__)), 'autoncore.py'))) else: print 'virtual_env_dir is NOT in environ' comm = "python %s " % \ (os.path.join(os.path.dirname(os.path.realpath(__file__)), 'autoncore.py')) comm += '--magic --target_repo "' + target_repo + '" --useremail "' + user + '" --changedfiles ' for c in changed_files: comm += '"' + c.strip() + '" ' if settings.test_conf['local']: print "running autoncode in the same thread" j = { 'action': 'magic', 'repo': target_repo, 'useremail': user, 'changedfiles': changed_files, 'created': str(datetime.now()), } rabbit.send(j) else: print 'running autoncore code as: ' + comm try: j = { 'action': 'magic', 'repo': target_repo, 'useremail': user, 'changedfiles': changed_files, 'created': str(datetime.now()), } rabbit.send(j) except Exception as e: sys.stdout.flush() sys.stderr.flush() error_msg = str(e) print 'error running generall all subprocess: ' + error_msg if 'execv() arg 2 must contain only strings' in error_msg: return { 'status': False, 'error': 'make sure that your repository filenames does not have accents or special characters' } else: return { 'status': False, 'error': 'generic error, please report the problem to us at [email protected]' } sys.stdout.flush() sys.stderr.flush() return {'status': True}