Ejemplo n.º 1
0
def skeletonize():
    '''Update Skeleton HTML5-Boilerplate.'''
    print green("Skeletonizing the project directory...")

    # Skeleton
    print blue("Installing skeleton HTML5 Boilerplate.")
    os.chdir(PROJ_DIR)
    sh.git.submodule.update(init=True)

    os.chdir(PROJ_DIR + "/skeleton")
    sh.git.pull("origin", "master")
    sh.rsync("-av", "images", "{0}/{1}/static/".format(PROJ_DIR,APP_NAME))
    sh.rsync("-av", "stylesheets",  "{0}/{1}/static/".format(PROJ_DIR,APP_NAME))
    sh.rsync("-av", "index.html",  "{0}/{1}/templates/base_t.html".format(PROJ_DIR,APP_NAME))
    os.chdir(PROJ_DIR)

    # Patch the base template with templating tags
    print blue("Patching the base template.")
    os.chdir(PROJ_DIR + "/{0}/templates/".format(APP_NAME))
    template_patch = open("base_t.patch".format(APP_NAME))
    sh.patch(strip=0, _in=template_patch)
    template_patch.close()
    os.chdir(PROJ_DIR)

    # Jquery
    print blue("Installing jquery 1.9.0.")
    os.chdir(PROJ_DIR + "/" + APP_NAME + "/static/js")
    sh.curl("http://code.jquery.com/jquery-1.9.0.min.js", O=True)
    os.chdir(PROJ_DIR)
Ejemplo n.º 2
0
 def apply_patch(self, filename):
     """
     Apply a patch from the current recipe directory into the current
     build directory.
     """
     print("Apply patch {}".format(filename))
     filename = join(self.recipe_dir, filename)
     sh.patch("-t", "-d", self.build_dir, "-p1", "-i", filename)
Ejemplo n.º 3
0
 def apply_patch(self, filename):
     """
     Apply a patch from the current recipe directory into the current
     build directory.
     """
     print("Apply patch {}".format(filename))
     filename = join(self.recipe_dir, filename)
     sh.patch("-t", "-d", self.build_dir, "-p1", "-i", filename)
Ejemplo n.º 4
0
def xxd_patch(old, new, patch_file):
    tmp_old = '/var/tmp/old_hex'
    sh.xxd('-p', old, _out=tmp_old)
    sh.tail('-n', '+2', patch_file, _out=patch_file+'.nohead')
    sh.patch(tmp_old, patch_file+'.nohead')

    if new:
        sh.xxd('-r', '-p', tmp_old, _out=new)
    else:
        sh.xxd('-r', '-p', tmp_old, _out=old)

    sh.rm('-f', tmp_old)
    sh.rm('-f', patch_file+'.nohead')
Ejemplo n.º 5
0
    def process_hunks(self, filename: Filename, hunks: List[Hunk]) -> None:
        auto_yes = False
        result = ""
        for hunk in hunks:
            if self.hunk_processor(filename, hunk) is False:
                continue

            if not self.silent:
                for line in hunk:
                    if line.startswith("---"):
                        click.secho(line, fg="red", bold=True)
                    elif line.startswith("+++"):
                        click.secho(line, fg="green", bold=True)
                    elif line.startswith("-"):
                        click.secho(line, fg="red")
                    elif line.startswith("+"):
                        click.secho(line, fg="green")
                    else:
                        click.echo(line)

                if self.interactive:
                    if auto_yes:
                        click.echo(f"Applying remaining hunks to {filename}")
                        result = "y"
                    else:
                        result = prompt_user("Apply this hunk", "ynqad", "n")

                    self.log_debug(f"result = {result}")

                    if result == "q":
                        raise BowlerQuit()
                    elif result == "d":
                        break  # skip all remaining hunks
                    elif result == "n":
                        continue
                    elif result == "a":
                        auto_yes = True
                        result = "y"
                    elif result != "y":
                        raise ValueError("unknown response")

            if result == "y" or self.write:
                patch = ("\n".join(hunk) + "\n").encode("utf-8")
                args = ["patch", "-u", filename]
                self.log_debug(f"running {args}")
                try:
                    sh.patch("-u", filename, _in=patch)  # type: ignore
                except sh.ErrorReturnCode:
                    log.exception("failed to apply patch hunk")
                    return  # TODO: better response?
Ejemplo n.º 6
0
 def apply_hunks(self, accepted_hunks, filename):
     if accepted_hunks:
         accepted_hunks = f"--- {filename}\n+++ {filename}\n{accepted_hunks}"
         args = ["patch", "-u", filename]
         self.log_debug(f"running {args}")
         try:
             sh.patch(*args[1:],
                      _in=accepted_hunks.encode("utf-8"))  # type: ignore
         except sh.ErrorReturnCode as e:
             if e.stderr:
                 err = e.stderr.strip().decode("utf-8")
             else:
                 err = e.stdout.strip().decode("utf-8")
                 if "saving rejects to file" in err:
                     err = err.split("saving rejects to file")[1]
                     log.exception(
                         f"hunks failed to apply, rejects saved to{err}")
                     return
             log.exception(f"failed to apply patch hunk: {err}")
Ejemplo n.º 7
0
 def apply_hunks(self, accepted_hunks, filename):
     if accepted_hunks:
         accepted_hunks = "--- {}\n+++ {}\n{}".format(
             filename, filename, accepted_hunks)
         args = ["patch", "-u", filename]
         self.log_debug("running {}".format(args))
         try:
             sh.patch(*args[1:],
                      _in=accepted_hunks.encode("utf-8"))  # type: ignore
         except sh.ErrorReturnCode as e:
             if e.stderr:
                 err = e.stderr.strip().decode("utf-8")
             else:
                 err = e.stdout.strip().decode("utf-8")
                 if "saving rejects to file" in err:
                     err = err.split("saving rejects to file")[1]
                     log.exception(
                         "hunks failed to apply, rejects saved to{}".format(
                             err))
                     return
             log.exception("failed to apply patch hunk: {}".format(err))
Ejemplo n.º 8
0
 def build_python(self):
     os.chdir(str(BUILD_DIR))
     print("Building Python {}".format(PYTHON_VERSION))
     print(
         tar(wget(
             '-O-',
             'https://www.python.org/ftp/python/{0}/Python-{0}.tar.xz'.
             format(PYTHON_VERSION)),
             "xJ",
             _err_to_out=True))
     os.chdir(str(BUILD_DIR / "Python-{}".format(PYTHON_VERSION)))
     print(patch('-i', str(CWD / 'macosx' / 'osx-setup.patch'), 'setup.py'))
     print(
         sh.Command('./configure')(prefix=str(BUILD_DIR / 'python'),
                                   _err_to_out=True))
     print(sh.Command('make')('-j4', _err_to_out=True))
     print(sh.Command('make')('install', _err_to_out=True))
     shutil.rmtree(str(BUILD_DIR / 'python' / 'lib' / 'python3.5' / 'test'))
Ejemplo n.º 9
0
def justPatch(patchText, fileToPatch):
    sh.patch(fileToPatch, **{"ignore-whitespace": True, "_in": patchText})
Ejemplo n.º 10
0
def patchCmd(patchText: str, fileToPatch: Path):
	sh.patch(fileToPatch, **{"ignore-whitespace": True, "_in": patchText})
Ejemplo n.º 11
0
def patch(old, new, patch_file):
    if new:
        sh.cp('-f', old, new)
        sh.patch(new, patch_file)
    else:
        sh.patch(old, patch_file)