Esempio n. 1
0
    configure_dns,
    ensure_db_exists,
    get_remote,
    get_wp_config,
    install_outer_files,
    make_replace_map,
    patch_config,
    read_config,
    restore_db,
    restore_files,
    run_post_install,
    run_queries,
)
from luh3417.utils import make_doer, run_main, setup_logging

doing = make_doer("luh3417.restore")


def parse_args(args: Optional[Sequence[str]] = None) -> Namespace:
    """
    Parse arguments from CLI
    """

    parser = ArgumentParser(description="Restores a snapshot")

    parser.add_argument("-p",
                        "--patch",
                        help="A settings patch file",
                        type=parse_location)
    parser.add_argument(
        "-a",
Esempio n. 2
0
from argparse import ArgumentParser
from typing import Optional, Sequence, Text

from luh3417.serialized_replace import walk
from luh3417.utils import make_doer, run_main, setup_logging

doing = make_doer("luh3417.replace")


def parse_args(argv: Optional[Sequence[Text]] = None):
    parser = ArgumentParser(description="Seeks and replaces serialized values")

    parser.add_argument("-i", "--input", required=True, help="Input file name")
    parser.add_argument("-o", "--output", required=True, help="Output file name")
    parser.add_argument("-b", "--before", nargs="+", help="String(s) to look for")
    parser.add_argument("-a", "--after", nargs="+", help="String(s) to replace by")
    parser.add_argument(
        "-c", "--charset", default="utf-8", help="What charset to use to read the file"
    )

    args = parser.parse_args(argv)

    if len(args.before) != len(args.after):
        parser.error("Not the same number of --before and --after")
        exit(1)

    return args


def main(argv: Optional[Sequence[Text]] = None):
    args = parse_args(argv)
Esempio n. 3
0
import json
from argparse import ArgumentParser, ArgumentTypeError, Namespace
from os.path import exists
from tempfile import NamedTemporaryFile
from typing import Optional, Sequence, Text

from luh3417.luhfs import parse_location
from luh3417.luhphp import parse_wp_config
from luh3417.restore.__main__ import main as restore
from luh3417.snapshot.__main__ import main as snapshot
from luh3417.transfer import UnknownEnvironment, apply_wp_config
from luh3417.utils import import_file, make_doer, run_main, setup_logging

doing = make_doer("luh3417.transfer")


def generator_validator(file_path: Text):
    """
    Validates that the generator module exists and has all the required
    methods
    """

    if not exists(file_path):
        raise ArgumentTypeError(f"File {file_path} could not be found")

    try:
        module = import_file("generator", file_path)
    except SyntaxError:
        doing.logger.exception("Syntax error in generator")
        raise ArgumentTypeError(f"File {file_path} has a syntax error")
    except ImportError:
Esempio n. 4
0
import json
from argparse import ArgumentParser, Namespace
from datetime import datetime
from os.path import join
from tempfile import TemporaryDirectory
from typing import Dict, Optional, Sequence, Text

from luh3417.luhfs import Location, parse_location
from luh3417.luhphp import parse_wp_config
from luh3417.luhsql import create_from_source
from luh3417.snapshot import copy_files
from luh3417.utils import make_doer, run_main, setup_logging

doing = make_doer("luh3417.snapshot")


def parse_args(args: Optional[Sequence[str]] = None) -> Namespace:
    """
    Parse arguments fro the snapshot
    """

    parser = ArgumentParser(
        description=("Takes a snapshot of a WordPress website remotely and "
                     "stores it to either a local or a remote location. This "
                     "requires rsync, php-cli and mysqldump"))

    parser.add_argument(
        "source",
        help=("Source directory for the WordPress installation dir. Syntax: "
              "`/var/www` or `user@host:/var/www`"),
        type=parse_location,
Esempio n. 5
0
from shlex import quote
from shutil import rmtree
from subprocess import DEVNULL, PIPE, Popen, TimeoutExpired
from tempfile import mkdtemp
from typing import Dict, Optional, Text, Tuple, Union

from luh3417.utils import make_doer

doing = make_doer("luh3417.luhssh")


def make_ssh_args(
    user: Text,
    host: Text,
    port: Union[int, Text, None] = None,
    options: Optional[Dict] = None,
    compress: bool = False,
    forward_agent: bool = False,
    nothing: bool = False,
):
    """
    Generates the appropriate SSH CLI args

    :param user: Username
    :param host: Host
    :param port: Port number (None to use default)
    :param options: SSH options (passed using -o)
    :param compress: Compress the connection
    :param forward_agent: Enable agent forwarding
    :param nothing: Just open the connection, don't run anything
    """