Mercurial > piecrust2
annotate piecrust/admin/scm/base.py @ 1188:a7c43131d871
bake: Fix file write flushing problem with Python 3.8+
Writing the cache files fails in Python 3.8 because it looks like flushing
behaviour has changed. We need to explicitly flush. And even then, in very
rare occurrences, it looks like it can still run into racing conditions,
so we do a very hacky and ugly "retry" loop when fetching cached data :(
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 15 Jun 2021 22:36:23 -0700 |
parents | 5e91bc0e3b4d |
children |
rev | line source |
---|---|
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 class RepoStatus(object): |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 def __init__(self): |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 self.new_files = [] |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 self.edited_files = [] |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 class SourceControl(object): |
598
3cec8634209a
admin: Ability to configure SCM stuff per site.
Ludovic Chabant <ludovic@chabant.com>
parents:
587
diff
changeset
|
10 def __init__(self, root_dir, cfg): |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 self.root_dir = root_dir |
598
3cec8634209a
admin: Ability to configure SCM stuff per site.
Ludovic Chabant <ludovic@chabant.com>
parents:
587
diff
changeset
|
12 self.config = cfg |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 def getStatus(self): |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 raise NotImplementedError() |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 |
598
3cec8634209a
admin: Ability to configure SCM stuff per site.
Ludovic Chabant <ludovic@chabant.com>
parents:
587
diff
changeset
|
17 def commit(self, paths, message, *, author=None): |
659
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
18 if not message: |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
19 raise ValueError("No message specified for committing changes.") |
598
3cec8634209a
admin: Ability to configure SCM stuff per site.
Ludovic Chabant <ludovic@chabant.com>
parents:
587
diff
changeset
|
20 author = author or self.config.get('author') |
3cec8634209a
admin: Ability to configure SCM stuff per site.
Ludovic Chabant <ludovic@chabant.com>
parents:
587
diff
changeset
|
21 self._doCommit(paths, message, author) |
3cec8634209a
admin: Ability to configure SCM stuff per site.
Ludovic Chabant <ludovic@chabant.com>
parents:
587
diff
changeset
|
22 |
3cec8634209a
admin: Ability to configure SCM stuff per site.
Ludovic Chabant <ludovic@chabant.com>
parents:
587
diff
changeset
|
23 def _doCommit(self, paths, message, author): |
587
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 raise NotImplementedError() |
d4a01a023998
admin: Add "FoodTruck" admin panel from the side experiment project.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
659
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
26 |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
27 def _s(strs): |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
28 """ Convert a byte array to string using UTF8 encoding. """ |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
29 if strs is None: |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
30 return None |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
31 assert isinstance(strs, bytes) |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
32 return strs.decode('utf8') |
a77b4656c602
internal: Move some basic FoodTruck SCM code to the base.
Ludovic Chabant <ludovic@chabant.com>
parents:
598
diff
changeset
|
33 |