Skip to content

link.config

Config()

Bases: BipObject

Server Config Bip object.

The server config should be created with link.specials.setup() in order to get the best default values.

Attributes:

Name Type Description
uid str

Bip unique identifier (uuid4). Edition is forbidden if this is an existing (recorded in database) entity.

slug str

Human-readable unique identifier. Since the Config is a singleton (only one per Bip instance), the slug is always server-config.

bip_source str

Url to the Git repository of Bip. The repository must be public. Used for updates. Unless you want to use you own fork of Bip, you should be using the official repository url (https://git.blinkink.co.uk/bip/client.git)

content_source str

Url to your Git repository for content. The repository must be public.

version str

The version used for the Bip instance clients. Must be latest or a valid Git tag name, in the semver format (vX.X.X).

enable_announcement bool

If True, an announcement is shown to all clients through the Launcher app.

announcement_message str

If enable_announcement is set to True, the message that will be displayed.

announcement_uid str

Announcement unique identifier (uuid4). Useful for determining if an announcement has been seen by a user. This is automatically generated if the announcement has been modified.

announcement_level str

If enable_announcement is set to True, the level of the announcement. Value can be: - "info" (wink.INFO) - "error" (wink.ERROR) - "warning" (wink.WARNING)

closable_announcement bool

If enable_announcement is set to True, defines if the announcement can be dismissed by users.

active_project_timeout int

In days, defines after how many days of inactivity the active project of a user is cleared (set to none).

Source code in client/bip/link/config.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def __init__(self):
    super(Config, self).__init__()
    self.uid = None
    self.slug = "server-config"

    self.bip_source: str = ""
    self.content_source: str = ""
    self.version: str = ""
    self.enable_announcement: bool = False
    self.announcement_message: str = ""
    self.announcement_uid: str = ""
    self.announcement_level: str = ""
    self.closable_announcement: bool = True
    self.active_project_timeout: int = 7
    self.offline: bool = False
    self._permissions: str = ""
    self.python_package_repository: str = ""
    self._compatibility_version: str = ""

is_announcement_modified property

Tells if any announcement setting has been modified.

Returns:

Name Type Description
bool

True if modified, False otherwise.

clear_announcement()

Deletes the current announcement if any

Source code in client/bip/link/config.py
226
227
228
229
230
231
def clear_announcement(self):
    """Deletes the current announcement if any"""
    self.announcement_message = None
    self.announcement_uid = None
    self.announcement_level = None
    self.closable_announcement = None

save()

Saves a Config object.

If the object is not floating (exists in the database) and has not been modified, nothing will be done.

If floating, the uid is automatically generated.

If not specified, the unique slug is automatically generated from the name.

Raises:

Type Description
ValueError
  • bip_source is not a valid (or public) Git repository.
  • content_source is not a valid (or public) Git repository.
  • announcement_level is invalid.
  • version is not "latest" and is not found in the bip_source tags.
Source code in client/bip/link/config.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
@permission("edit_config")
def save(self):
    """Saves a `Config` object.

    If the object is not floating (exists in the database)
    and has not been modified, nothing will be done.

    If floating, the uid is automatically generated.

    If not specified, the unique slug is automatically
    generated from the name.

    Raises:
        ValueError:
            - bip_source is not a valid (or public) Git repository.
            - content_source is not a valid (or public) Git repository.
            - announcement_level is invalid.
            - version is not "latest" and is not found in the `bip_source` tags.
    """
    if not self._is_modified:
        return

    # If announcement changed (message, level, closable), new uid
    if self.is_announcement_modified:
        self.announcement_uid = str(uuid4())

    # If announcement disabled: clear announcement
    if not self.enable_announcement:
        self.clear_announcement()

    if not self.uid:
        self._generate_uid()

    if self.is_version_modified:
        with open_repository(self.bip_source, tag=self.version) as path:
            compatibility_breakpoint = None
            package_file = Path(path) / "bip" / "__init__.py"
            if not package_file.exists():
                raise ValueError(
                    f"The repository {self.bip_source} does not have a bip/__init__.py file."
                )

            with open(package_file, mode="r") as file_content:
                lines = file_content.readlines()

        for line in lines:
            if not line.startswith("compatibility_breakpoint"):
                continue

            result = re.findall('"([^"]*)"', line)
            if not result:
                continue

            result = result[0]
            try:
                version.Version(result)
            except version.InvalidVersion:
                continue
            else:
                compatibility_breakpoint = result

        if compatibility_breakpoint:
            self._compatibility_version = compatibility_breakpoint
        else:
            raise ValueError(
                f"The repository {self.bip_source} does not have the mandatory compatibility_breakpoint variable set in bip/__init__.py."
            )

    _validate(self)

    return sink.config.save(self.to_dict())

get(force=False)

Gets the current Bip instance server config.

Parameters:

Name Type Description Default
autogen bool

If set to true, the getter automatically returns an empty Config

required

Returns:

Name Type Description
Config

If found and/or if not found but autogen is set to true.

bool

If not found and autogen is set to false.

Source code in client/bip/link/config.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def get(force=False):
    """Gets the current Bip instance server config.

    Args:
        autogen (bool, optional): If set to true, the getter automatically returns an empty Config

    Returns:
        Config: If found and/or if not found but `autogen` is set to true.
        bool: If not found and `autogen` is set to false.

    """
    global config

    if not config or force:
        data = sink.config.get()
        if data:
            config = Config.from_dict(data)
        else:
            raise LookupError(f"There is no config for the current instance.")

    return config