def generate_init(target_dir, include_to_git=True): if not os.path.exists(target_dir): os.makedirs(target_dir) init_file = os.path.join(target_dir, '__init__.py') with open(init_file, 'w') as target_file_handler: target_file_handler.write('\"\"\" Init file \"\"\"\n') if include_to_git: run_cmd('git add "%s"' % (target_dir, ))
def get_upstream_name(path): get_upstream_name = ' git rev-parse --abbrev-ref --symbolic-full-name @{u}' get_upstream_command = 'cd "' + path + '" && ' + get_upstream_name # print(get_upstream_command) upstream = run_cmd(get_upstream_command) return upstream
def get_diverge_commits_upstream_to_HEAD(path): upstream = get_upstream_name(path) get_diverge_commits = 'git log ' + upstream + '..HEAD --pretty=oneline | wc -l' get_diverge_commits_command = 'cd "' + path + '" && ' + get_diverge_commits diverge_commits = run_cmd(get_diverge_commits_command) return diverge_commits
def push_commits_to_upstream(path): upstream = get_upstream_name(path) upstream = upstream.replace('/', ' ') push_commits = 'git push ' + upstream + '' push_commits_command = 'cd "' + path + '" && ' + push_commits # print(push_commits_command) push_commits_output = run_cmd(push_commits_command) return push_commits_output
def get_today_commits(path): get_today_commits = 'git log HEAD --pretty=oneline --since=midnight' get_today_commits_command = 'cd "' + path + '" && ' + get_today_commits today_commits_output = run_cmd(get_today_commits_command) today_commits_list = today_commits_output.split('\n') today_commits = [] for i in range(0, len(today_commits_list)): today_commits_list[i] = today_commits_list[i].strip() if today_commits_list[i] != "": today_commits.append(today_commits_list[i]) return today_commits
def search_projects(): search_path = sys.argv[1] assets_file_path = [] psettings_file_path = [] for root, subFolders, files in os.walk(search_path): for folder in subFolders: if folder == 'Assets': assets_file_path.append(root) if folder == "ProjectSettings": psettings_file_path.append(root) u_paths = [] for f in assets_file_path: for f2 in psettings_file_path: if f == f2: u_paths.append(f) break print('Found %s Unity projects\n' % (len(u_paths))) shader_flag = verify_flag("--shader") csharp_flag = verify_flag("--csharp") no_flag = not csharp_flag and not shader_flag show_cs_files = csharp_flag or no_flag show_shader_files = shader_flag or no_flag for u in u_paths: project_path = u project_name = os.path.basename(project_path) print('Project ' + project_name) print(' Path ' + project_path) project_path = os.path.join(project_path, "Assets/") if show_cs_files: cs_number_cmd = 'find "' + project_path + '" -name "*.cs" | wc -l' cs_number_output = run_cmd(cs_number_cmd) cs_lines_cmd = '(find "' + project_path + '" -name "*.cs" | xargs -I {} cat {}) | wc -l' cs_lines_output = run_cmd(cs_lines_cmd) print(' Total CS scripts: ' + cs_number_output.strip() + ' (LOC: ' + \ cs_lines_output.strip() + ')') if show_shader_files: shader_number_cmd = 'find "' + project_path + '" -name "*.shader" | wc -l' shader_number_output = run_cmd(shader_number_cmd) shader_lines_cmd = '(find "' + project_path + '" -name "*.shader" | xargs -I {} cat {}) | wc -l' shader_lines_output = run_cmd(shader_lines_cmd) print(' Total shader scripts: ' + shader_number_output.strip() + ' (LOC: ' + \ shader_lines_output.strip() + ')') if shader_flag: shader_files_cmd = 'find "' + project_path + '" -name "*.shader"' shader_files_output = run_cmd(shader_files_cmd) shader_files = shader_files_output.split("\n") for shader_file in shader_files: shader_name = os.path.basename(shader_file) print(" - %s" % shader_name)
def get_unstaged_files(repo_path): get_unstaged_files = 'git diff --numstat | wc -l' get_unstaged_command = 'cd "' + repo_path + '" && ' + get_unstaged_files unstaged = run_cmd(get_unstaged_command) return unstaged