Created
July 31, 2015 12:24
-
-
Save bmangesh/1d7b448afb6a24cdd0ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
win_path = "C:/Users/mangesh.b/SonarAnalysis" | |
linux_path = "/home/ec2-user/SonarAnalysis" | |
import os, platform, git, subprocess | |
from array import * | |
ostype=os.name | |
def create_dir(): | |
if ostype == 'nt': | |
if not os.path.exists(win_path): | |
os.makedirs(win_path) | |
print "Windows" | |
else: | |
if not os.path.exists(linux_path): | |
os.makedirs(linux_path) | |
print "linux" | |
def clone_git(): | |
clone_mapping = {'java_project': 'https://gist.github.com/ec1ef591fb43d07e78ea.git', | |
'csharp_project': 'https://gist.github.com/da3e41621b28d7fd3594.git'} | |
language_mapping = {'java_project': ['com.java', 'simple java project', 'java'], | |
'csharp_project': ['com.cs', 'simple cs project', 'cs']} | |
if ostype == 'nt' and os.path.exists(win_path): | |
for dir, clone in clone_mapping.iteritems(): | |
path = os.path.join(win_path, dir) | |
if os.path.exists(path): | |
os.chdir(path) | |
data = os.listdir(path)[1] | |
print data | |
os.chdir(data) | |
subprocess.call(["git", "pull"]) | |
print "done..!" | |
else: | |
os.mkdir(path) | |
os.chdir(path) | |
text_file = open("sonar-project.properties", "w") | |
msg = "sonar.projectKey={} \nsonar.projectVersion=1.0\nsonar.sources=.\nsonar.projectName={}\nJava sonar.language={}".format(*language_mapping.get(dir, [])) | |
text_file.write(msg) | |
text_file.close() | |
git.Git().clone(clone) | |
cmd = 'sonar-runner' | |
os.system(cmd) | |
else: | |
if os.path.exists(linux_path): | |
for dir, clone in clone_mapping.iteritems(): | |
path = os.path.join(linux_path, dir) | |
if os.path.exists(path): | |
os.chdir(path) | |
data = os.listdir(path)[1] | |
os.chdir(data) | |
subprocess.call(["git", "pull"]) | |
else: | |
os.mkdir(path) | |
os.chdir(path) | |
git.Git().clone(clone) | |
create_dir() | |
clone_git() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment