API reference
conf_path(create_if_missing=False)
Returns the path found for the pg_service.conf on the system as string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
create_if_missing
|
bool | None
|
Whether to create the file (and eventually its parent folders) if the file does not exist. |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
path to the pg_service.conf file as string |
Source code in pgserviceparser/__init__.py
copy_service_settings(source_service_name, target_service_name, conf_file_path=None)
Copy all settings from one service to another.
If the target service does not exist, it is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_service_name
|
str
|
name of the service to copy settings from |
required |
target_service_name
|
str
|
name of the service to copy settings to |
required |
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True on success |
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
ServiceNotFound
|
when the source service is not found |
PermissionError
|
when the service file is read-only |
Source code in pgserviceparser/__init__.py
create_service(service_name, settings, conf_file_path=None)
Create a new service in the service file.
If the service already exists, nothing is changed and False is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
service name |
required |
settings
|
dict
|
settings dict defining the service config |
required |
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the service was created, False if it already existed |
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
PermissionError
|
when the service file is read-only |
Source code in pgserviceparser/__init__.py
full_config(conf_file_path=None)
Returns full pgservice config as configparser.ConfigParser().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conf_file_path
|
Path | None
|
path to configuration file to load. If None the |
None
|
Returns:
| Type | Description |
|---|---|
ConfigParser
|
pg services loaded as ConfigParser |
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
Source code in pgserviceparser/__init__.py
remove_service(service_name, conf_file_path=None)
Remove a complete service from the service file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
service name |
required |
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
ServiceNotFound
|
when the service is not found |
PermissionError
|
when the service file is read-only |
Source code in pgserviceparser/__init__.py
rename_service(old_name, new_name, conf_file_path=None)
Rename a service in the service file.
The service settings are preserved under the new name and the old section is removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
current service name |
required |
new_name
|
str
|
desired service name |
required |
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
ServiceNotFound
|
when the old service is not found |
PermissionError
|
when the service file is read-only |
Source code in pgserviceparser/__init__.py
service_config(service_name, conf_file_path=None)
Returns the config from the given service name as a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
service name |
required |
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
service settings as dictionary |
Raises:
| Type | Description |
|---|---|
ServiceNotFound
|
when the service is not found |
Source code in pgserviceparser/__init__.py
service_names(conf_file_path=None, sorted_alphabetically=False)
Returns all service names in a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
sorted_alphabetically
|
bool
|
whether to sort the names alphabetically (case-insensitive), defaults to False |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list of every service registered |
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
Source code in pgserviceparser/__init__.py
write_service(service_name, settings, conf_file_path=None, create_if_not_found=False)
Writes a complete service to the service file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
service name |
required |
settings
|
dict
|
settings dict defining the service config |
required |
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
create_if_not_found
|
bool
|
option to create a new service if it does not exist yet. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
ServiceNotFound
|
when the service is not found |
PermissionError
|
when the service file is read-only |
Returns:
| Type | Description |
|---|---|
dict
|
existing or newly created service as dictionary |
Source code in pgserviceparser/__init__.py
write_service_setting(service_name, setting_key, setting_value, conf_file_path=None)
Writes a service setting to the service file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
service name |
required |
setting_key
|
str
|
key |
required |
setting_value
|
str
|
value |
required |
conf_file_path
|
Path | None
|
path to the pg_service.conf. If None the |
None
|
Raises:
| Type | Description |
|---|---|
ServiceFileNotFound
|
when the service file is not found |
ServiceNotFound
|
when the service is not found |
PermissionError
|
when the service file is read-only |
Source code in pgserviceparser/__init__.py
write_service_to_text(service_name, settings)
Returns the complete service settings as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_name
|
str
|
service name |
required |
settings
|
dict
|
settings dict defining the service config |
required |
Returns:
| Type | Description |
|---|---|
str
|
Service settings as a string |