示例#1
0
def start(args):
    """Set up the Geofront server URL."""
    for path in load_config_paths(CONFIG_RESOURCE):
        path = os.path.join(path.decode(), SERVER_CONFIG_FILENAME)
        if os.path.isfile(path):
            message = 'Geofront server URL is already configured: ' + path
            if args.force:
                print(message + '; overwriting...', file=sys.stderr)
            else:
                parser.exit(message)
    while True:
        server_url = input('Geofront server URL: ')
        if not server_url.startswith(('https://', 'http://')):
            print(server_url, 'is not a valid url.')
            continue
        elif not server_url.startswith('https://'):
            cont = input('It is not a secure URL. '
                         'https:// is preferred over http://. '
                         'Continue (y/N)? ')
            if cont.strip().lower() != 'y':
                continue
        break
    server_config_filename = os.path.join(
        save_config_path(CONFIG_RESOURCE).decode(), SERVER_CONFIG_FILENAME)
    with open(server_config_filename, 'w') as f:
        print(server_url, file=f)
    authenticate.call(args)
示例#2
0
def start(args):
    """Set up the Geofront server URL."""
    for path in load_config_paths(CONFIG_RESOURCE):
        path = os.path.join(path.decode(), SERVER_CONFIG_FILENAME)
        if os.path.isfile(path):
            message = 'Geofront server URL is already configured: ' + path
            if args.force:
                print(message + '; overwriting...', file=sys.stderr)
            else:
                parser.exit(message)
    while True:
        server_url = input('Geofront server URL: ')
        if not server_url.startswith(('https://', 'http://')):
            print(server_url, 'is not a valid url.')
            continue
        elif not server_url.startswith('https://'):
            cont = input('It is not a secure URL. '
                         'https:// is preferred over http://. '
                         'Continue (y/N)? ')
            if cont.strip().lower() != 'y':
                continue
        break
    server_config_filename = os.path.join(
        save_config_path(CONFIG_RESOURCE).decode(),
        SERVER_CONFIG_FILENAME
    )
    with open(server_config_filename, 'w') as f:
        print(server_url, file=f)
    authenticate.call(args)
示例#3
0
def get_config_files():
    """ return the path to the config files or and empty list.
    The search path is based on the paths returned by load_config_paths
    but it's returned in reverse order (e.g: /etc/xdg first).
    """
    config_files = []
    for xdg_config_dir in load_config_paths("ubuntuone"):
        xdg_config_dir = unicode_path(xdg_config_dir)
        config_file = os.path.join(xdg_config_dir, CONFIG_FILE)
        if os.path.exists(config_file):
            config_files.append(config_file)

        config_logs = os.path.join(xdg_config_dir, CONFIG_LOGS)
        if os.path.exists(config_logs):
            config_files.append(config_logs)

    # reverse the list as load_config_paths returns the user dir first
    config_files.reverse()
    # if we are running from a branch, get the config files from it too
    config_file = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, "data", CONFIG_FILE)
    if os.path.exists(config_file):
        config_files.append(config_file)

    config_logs = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, "data", CONFIG_LOGS)
    if os.path.exists(config_logs):
        config_files.append(config_logs)

    return config_files
示例#4
0
def get_server_url():
    for path in load_config_paths(CONFIG_RESOURCE):
        path = os.path.join(path.decode(), SERVER_CONFIG_FILENAME)
        if os.path.isfile(path):
            with open(path) as f:
                return f.read().strip()
    parser.exit('Geofront server URL is not configured yet.\n'
                'Try `{0} start` command.'.format(parser.prog))
示例#5
0
def get_server_url():
    for path in load_config_paths(CONFIG_RESOURCE):
        path = os.path.join(path.decode(), SERVER_CONFIG_FILENAME)
        if os.path.isfile(path):
            with open(path) as f:
                return f.read().strip()
    parser.exit('Geofront server URL is not configured yet.\n'
                'Try `{0} start` command.'.format(parser.prog))
示例#6
0
def get_directory() -> str:
    try:
        conf = _basedir.load_config_paths(soft_name)
        for p in conf:
            with open('/'.join([str(p, 'utf-8'), conf_file])) as f:
                c = _decoder.load(f).get('config')
                if c is not None:
                    d = c.get('directory')
                    if d is not None:
                        return _path.expandvars(_path.expanduser(d))
        #default
        return str(_basedir.save_data_path(soft_name), 'utf-8')
    except FileNotFoundError:
        return str(_basedir.save_data_path(soft_name), 'utf-8')
示例#7
0
def get_filename_ignore() -> str:
    try:
        conf = _basedir.load_config_paths(soft_name)
        for p in conf:
            with open('/'.join([str(p, 'utf-8'), conf_file])) as f:
                c = _decoder.load(f).get('config')
                if c is not None:
                    l = c.get('exclude_files')
                    if l is not None:
                        return l
        #default
        return ['README.md']
    except FileNotFoundError:
        return ['README.md']
示例#8
0
def get_cert_dir():
    """Return directory containing certificate files."""

    if getattr(sys, "frozen", None) is not None:
        if sys.platform == "win32":
            ssl_cert_location = list(load_config_paths("ubuntuone"))[1]
        elif sys.platform == "darwin":
            main_app_dir = "".join(__file__.partition(".app")[:-1])
            main_app_resources_dir = os.path.join(main_app_dir, "Contents",
                                                  "Resources")
            ssl_cert_location = main_app_resources_dir
    elif any(plat in sys.platform for plat in ("win32", "darwin")):
        pkg_dir = os.path.dirname(__file__)
        src_tree_path = os.path.dirname(os.path.dirname(pkg_dir))
        ssl_cert_location = os.path.join(src_tree_path, "data")
    else:
        ssl_cert_location = '/etc/ssl/certs'

    return ssl_cert_location
def get_cert_dir():
    """Return directory containing certificate files."""

    if getattr(sys, "frozen", None) is not None:
        if sys.platform == "win32":
            ssl_cert_location = list(load_config_paths(
                    "ubuntuone"))[1]
        elif sys.platform == "darwin":
                main_app_dir = "".join(__file__.partition(".app")[:-1])
                main_app_resources_dir = os.path.join(main_app_dir,
                                                      "Contents",
                                                      "Resources")
                ssl_cert_location = main_app_resources_dir
    elif any(plat in sys.platform for plat in ("win32", "darwin")):
        pkg_dir = os.path.dirname(__file__)
        src_tree_path = os.path.dirname(os.path.dirname(pkg_dir))
        ssl_cert_location = os.path.join(src_tree_path,
                                         "data")
    else:
        ssl_cert_location = '/etc/ssl/certs'

    return ssl_cert_location
示例#10
0
 def test_load_config_paths_filter(self):
     """Since those folders don't exist, this should be empty."""
     self.assertEqual(list(basedir.load_config_paths("x")), [])
示例#11
0
 def test_load_config_paths_filter(self):
     """Since those folders don't exist, this should be empty."""
     self.assertEqual(list(basedir.load_config_paths("x")), [])