Skip to content

Commit 76546fb

Browse files
committed
Fix an issue with demarcation in scripts (like this one) that use it for other purposes.
1 parent 267dd11 commit 76546fb

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

Pckgd/Pckgd.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Title: Pckgd, A Package Manager
33
# Description: A module for managing packages and their updates.
44
# Updates from: GitHub/TenthPres/TouchPointScripts/Pckgd/Pckgd.py
5-
# Version: 0.0.5
5+
# Version: 0.0.6
66
# License: AGPL-3.0
77
# Author: James at Tenth
8+
# Editable: False
89

910
# Do not make edits to this file. They will be overwritten during updates.
1011

@@ -70,6 +71,12 @@ def parse_headers(self):
7071
self.headers[key] = value
7172
elif Pckgd.do_not_edit_demarcation in line:
7273
break
74+
75+
if 'Editable' in self.headers and self.headers['Editable'].lower() in ['false', '0', 'no', 'off']:
76+
self.headers['Editable'] = False
77+
else:
78+
self.headers['Editable'] = True
79+
7380
return
7481

7582
def get_action_buttons(self):
@@ -325,11 +332,11 @@ def do_update(self, new_pckg):
325332
# If using demarcation, preserve anything above it (the "preamble").
326333
preamble = None
327334
new_body = new_pckg.body
328-
if Pckgd.do_not_edit_demarcation in self.body:
335+
if Pckgd.do_not_edit_demarcation in self.body and self.headers['Editable'] == True:
329336
preamble = self.body.split(Pckgd.do_not_edit_demarcation, 1)[0]
330337

331338
# Assemble new body with old preamble.
332-
if preamble is not None and Pckgd.do_not_edit_demarcation in new_pckg.body:
339+
if preamble is not None and Pckgd.do_not_edit_demarcation in new_pckg.body and self.headers['Editable'] == True:
333340
new_body = new_pckg.body.split(Pckgd.do_not_edit_demarcation, 1)[-1].strip()
334341

335342
if preamble is not None:

Pckgd/README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,29 @@ be located in the first 100 lines of the script, and must be located immediately
1717
demarcation is used (explained below), the headers must be *above* the demarcation.
1818
The headers are:
1919

20-
- `# Pckgd` - Required as the first of these headers. No value. Identifies the file as part of a Pckgd package, and
20+
- `# Pckgd` Required as the first of these headers. No value. Identifies the file as part of a Pckgd package, and
2121
indicates where these headers are in the file. Without this header, the script won't be found in the query for
2222
packages, and the headers won't be found in the file.
23-
- `# Updates from:` - Required for updates. An identifier of where updates should come from. Two types of values are allowed:
23+
- `# Updates from:` Required for updates. An identifier of where updates should come from. Two types of values are allowed:
2424
- A URL to a text file: e.g. `# Updates from: https://example.com/mypackage-latest.txt`
2525
- A GitHub repository in the format `GitHub/username/repo/path/to/file.py`: e.g. `# Updates from: GitHub/TenthPres/TouchPointScripts/Pckgd/Pckgd.py`
26-
- `# Title:` - Optional, but recommended. The human-readable name of the package. This is the name shown in the UI.
27-
- `# Description:` - Optional, but recommended. A brief description of what the package does.
28-
- `# Depends on:` - Optional. A comma-separated list of other Pckgd scripts (with extensions) that this script depends
26+
- `# Title:` Optional, but recommended. The human-readable name of the package. This is the name shown in the UI.
27+
- `# Description:` Optional, but recommended. A brief description of what the package does.
28+
- `# Depends on:` Optional. A comma-separated list of other Pckgd scripts (with extensions) that this script depends
2929
on. For example, if a python script depends on a SQL file, this header might be something like `# Depends on: MyScript.sql`.
3030
When dependencies are defined, they will be provided as part of installation, provided they are available in the same
3131
source and directory as the current file.
32-
- `# Version:` - Optional. The current version of the script. Must contain hex characters and dots only (e.g. `1.0.0`, `2.1`, `2024.06.15`, `adcf1234`).
32+
- `# Version:` Optional. The current version of the script. Must contain hex characters and dots only (e.g. `1.0.0`, `2.1`, `2024.06.15`, `adcf1234`).
3333
- If not provided, a hash will be generated on a per-file basis to determine if a new version is available.
3434
- If a version is provided in the source file (e.g. on GitHub), only the version numbers will be compared, not the content of the script. Therefore, if you use this parameter, to make clients see a new update as being available, you *must* change the version number on the repository.
3535
- If you want every new update published on your repository to be treated as a new version, leave this header out.
36-
- `# License:` - Optional. The license under which the package is provided.
37-
- `# Author:` - Optional. The author of the package.
38-
- `# Header color:` - Optional. A hex color code (e.g. `#FF0000`) to use as the header color in the UI. If one is not provided, a color is generated from a hash of the file name.
39-
- `# Header image:` - Optional. A URL to an image to use as the header image in the UI.
36+
- `# License:` Optional. The license under which the package is provided.
37+
- `# Author:` Optional. The author of the package.
38+
- `# Header color:` Optional. A hex color code (e.g. `#FF0000`) to use as the header color in the UI. If one is not provided, a color is generated from a hash of the file name.
39+
- `# Header image:` Optional. A URL to an image to use as the header image in the UI.
40+
- `# Editable:` Optional, True or False. If your script contains the "stop editing" demarcation (explained below),
41+
*for other purposes*, you can set this to `False` to prevent confusion about whether the script is editable. Default
42+
is `True`.
4043

4144
### Examples
4245

0 commit comments

Comments
 (0)