Exemple #1
0
def create_table(args):
    if args.conf_path is None:
        args.conf_path = get_environ("DB_CONF_PATH")
    t = TableDB(conf_path=args.conf_path)
    suffix_comp = re.compile(r"\w+\.(json|function|procedure|trigger|view)$",
                             re.I)
    all_files = args.files
    if args.file_prefix is not None:
        all_files = map(lambda x: args.file_prefix + x, all_files)
    if args.directory is not None:
        desc_files = os.listdir(args.directory)
        all_files.extend(
            map(lambda x: os.path.join(args.directory, x), desc_files))
    for file_path in all_files:
        filename = os.path.split(file_path)[1]
        if suffix_comp.match(filename) is None:
            logger.warning(g_help("skip_file", file_path))
            continue
        logger.info(g_help("handle_file", file_path))
        check_file_exist(file_path)
        if file_path.endswith(".json"):
            r = t.create_from_json_file(file_path)
        else:
            with open(file_path) as rf:
                c = rf.read()
                ds = re.findall(r"(DROP[\s\S]+? IF EXISTS[\s\S]+?(;|\n))", c,
                                re.I)
                for item in ds:
                    t.execute(item[0])
                fs = re.findall(r"(CREATE[\s\S]+?(END;|END\n|$))", c)
                for item in fs:
                    t.execute(item[0])
Exemple #2
0
def find_one_port():
    args_man.add_argument("-s",
                          "--server",
                          dest="server",
                          help=g_help("server"),
                          choices=define_server.keys())
    args_man.add_argument("-p",
                          "--ports",
                          dest="ports",
                          help=g_help("port"),
                          nargs="*")

    args = args_man.parse_args()
    all_ports = []
    if args.server is not None:
        all_ports.extend(define_server[args.server])
    if args.ports is not None:
        for port in args.ports:
            ports = re.split(r"\D", port)
            ports = map(lambda x: int(x), filter(lambda x: len(x) > 0, ports))
            all_ports.extend(ports)
    for item in all_ports:
        logger.debug("check is listen %s" % item)
        if is_listen(item) is False:
            logger.info(item)
            sys.exit(0)
    sys.exit(1)
Exemple #3
0
def environ_format():
    arg_man.add_argument("-d",
                         "--directory",
                         dest="directory",
                         help=g_help("directory"),
                         metavar="directory")
    arg_man.add_argument("-p",
                         "--prefix",
                         dest="prefix",
                         help=g_help("prefix"),
                         metavar="prefix")
    arg_man.add_argument("-e",
                         "--end",
                         dest="end",
                         help=g_help("end"),
                         metavar="end")
    arg_man.add_argument("-f",
                         "--filter",
                         dest="filter",
                         help=g_help("filter"),
                         metavar="filter",
                         default=r"\S*")
    arg_man.add_argument("-i",
                         "-I",
                         "--input",
                         dest="input",
                         help=g_help("conf_file"),
                         metavar="conf_file",
                         action="append",
                         default=[])
    arg_man.add_argument("inputs",
                         metavar="conf_file",
                         nargs="*",
                         help=g_help("conf_file"))
    arg_man.add_argument("-m",
                         "--mode",
                         dest="mode",
                         help=g_help("mode"),
                         type=int,
                         choices=[1, 2],
                         default=1)

    if len(sys.argv) <= 1:
        sys.argv.append("-h")
    args = arg_man.parse_args()
    files = args.input
    files.extend(args.inputs)
    if args.directory is not None:
        files.extend(
            list_files(args.directory, args.prefix, args.end, args.filter))
    for item in files:
        logger.info("format %s" % item)
        rewrite_conf(item, args.mode)
        logger.info("format %s success\n" % item)
Exemple #4
0
def download_action(endpoint, oss_dir, oss_item, save_path, force=False, custom_dir=""):
    if os.path.exists(save_path) is True and force is False:
        logger.warning(g_help("exist", oss_item))
        return 0
    logger.info(g_help("download", oss_item, save_path))
    custom_url = ""
    if custom_dir != "":
        custom_url = get_download_url(endpoint, oss_item, oss_dir, custom_dir)
        code = head_url(custom_url)
        if code != 200:
            logger.debug(g_help("head_error", custom_url, code))
            custom_url = ""
    if custom_url == "":
        url = get_download_url(endpoint, oss_item, oss_dir)
        code = head_url(url)
        if code != 200:
            error_and_exit(g_help("head_error", url, code))
    else:
        url = custom_url
    cmd = ["curl", "-o", save_path, url]
    e_code = os.system(" ".join(cmd))
    return e_code
Exemple #5
0
def get_ip():

    default_ip = get_default_ip()
    logger.info(default_ip)