def install(args): # download git_args = copy.copy(args) git_args.name = n2nApp.name git_args.url = "[email protected]:ntop/n2n.git" git_args.branch = args.version n2n_root = git.clone(git_args) # compile with bash.enter(path.join(n2n_root, BUILD_DIR), create=True): CMAKE = ["cmake"] if args.system: CMAKE.append("-DCMAKE_INSTALL_PREFIX=" + args.install_dir) CMAKE.append("..") bash.shell_exec(*CMAKE) MAKE = [] if args.system: MAKE.append("sudo") MAKE.extend(["make", "-j${nproc}"]) if args.system: MAKE.append("install") bash.shell_exec(*MAKE) if args.system: # install n2n system init config bash.shell_exec("sudo cp -r ", N2N_CONF_DIR, "/") bash.shell_exec("sudo systemctl daemon-reload") bash.shell_exec("sudo update-rc.d n2n defaults")
def clone(args): bash.make_dirs(args.git_root) with bash.enter(args.git_root): if not path.exists(args.name): command = [ "git", "clone", "--recurse-submodules", args.url, args.name ] bash.shell_exec("git clone --recurse-submodules", args.url, args.name, check_error=True) if args.branch: with bash.enter(args.name): bash.shell_exec("git checkout", args.branch, check_error=True) return path.join(args.git_root, args.name)
def init_code(args): code_root = args.root or os.getcwd() code_path = path.join(code_root, args.name) code_core = path.join(bash.BBCODE_ROOT, "cpp") core_relative_path = path.relpath(code_core, start=code_path) with bash.enter(code_path, create=True): with open(path.join(code_path, "main.cpp"), "w") as f: f.write(MAIN_CODE) with open(path.join(code_path, "Makefile"), "w") as f: f.write(MAKEFILE.format_map( SafeDict(link_path=core_relative_path))) return code_path
def clean(args): for del_file in args.delete: logger.info("git delete " + del_file) bash.shell_exec( "git filter-branch --force --index-filter ", "\"git rm -rf --cached --ignore-unmatch {}\" ".format(del_file), "--prune-empty --tag-name-filter cat -- --all") if args.delete: logger.info("update all local branches") bash.shell_exec( "git for-each-ref --format='delete %(refname)' refs/original | ", "git update-ref --stdin") bash.shell_exec("git reflog expire --expire=now --all") logger.info("start git gc") bash.shell_exec("git gc --prune=now") bash.shell_exec("git count-objects -v") logger.info("push into remote repository") bash.shell_exec("git push origin --force --all") bash.shell_exec("git push origin --force --tags") with bash.enter(args.git_path): logger.info("list large file names") bash.shell_exec("git verify-pack -v .git/objects/pack/*.idx |", "sort -k 3 -nr |", "head -" + str(args.list_number), check_error=True) bash.shell_exec("git rev-list --objects --all |", "grep", "\"$(", "git verify-pack -v .git/objects/pack/*.idx |", "sort -k 3 -nr |", "head -" + str(args.list_number) + " |", "awk '{print$1}'", ")\"", check_error=True)
def init_leet_code(args): code_path = init_code(args) with bash.enter(code_path): with open(path.join(code_path, "main.cpp"), "w") as f: f.write(LC_MAIN_CODE)