python3-cyberfusion-file-support 1.3__tar.gz → 1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (13) hide show
  1. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/PKG-INFO +3 -3
  2. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/pyproject.toml +2 -2
  3. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/src/cyberfusion/FileSupport/__init__.py +28 -57
  4. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/src/python3_cyberfusion_file_support.egg-info/PKG-INFO +3 -3
  5. python3_cyberfusion_file_support-1.5/src/python3_cyberfusion_file_support.egg-info/requires.txt +2 -0
  6. python3_cyberfusion_file_support-1.3/src/python3_cyberfusion_file_support.egg-info/requires.txt +0 -2
  7. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/README.md +0 -0
  8. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/setup.cfg +0 -0
  9. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/src/cyberfusion/FileSupport/encryption.py +0 -0
  10. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/src/cyberfusion/FileSupport/exceptions.py +0 -0
  11. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/src/python3_cyberfusion_file_support.egg-info/SOURCES.txt +0 -0
  12. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/src/python3_cyberfusion_file_support.egg-info/dependency_links.txt +0 -0
  13. {python3_cyberfusion_file_support-1.3 → python3_cyberfusion_file_support-1.5}/src/python3_cyberfusion_file_support.egg-info/top_level.txt +0 -0
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: python3-cyberfusion-file-support
3
- Version: 1.3
3
+ Version: 1.5
4
4
  Summary: Library for idempotent writing to files.
5
5
  Author-email: Cyberfusion <support@cyberfusion.io>
6
6
  Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-file-support
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: python3-cyberfusion-common~=2.0
9
- Requires-Dist: python3-cyberfusion-queue-support~=1.3
9
+ Requires-Dist: python3-cyberfusion-queue-support~=1.7.0
10
10
 
11
11
  # python3-cyberfusion-file-support
12
12
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python3-cyberfusion-file-support"
7
- version = "1.3"
7
+ version = "1.5"
8
8
  description = "Library for idempotent writing to files."
9
9
  readme = "README.md"
10
10
  authors = [
@@ -12,7 +12,7 @@ authors = [
12
12
  ]
13
13
  dependencies = [
14
14
  "python3-cyberfusion-common~=2.0",
15
- "python3-cyberfusion-queue-support~=1.3",
15
+ "python3-cyberfusion-queue-support~=1.7.0",
16
16
  ]
17
17
 
18
18
  [project.urls]
@@ -1,7 +1,5 @@
1
1
  """Classes for files."""
2
2
 
3
- import difflib
4
-
5
3
  import os
6
4
 
7
5
  from typing import List, Optional, Union
@@ -35,20 +33,15 @@ class _DestinationFile:
35
33
  self.encryption_properties = encryption_properties
36
34
 
37
35
  @property
38
- def exists(self) -> bool:
36
+ def _exists(self) -> bool:
39
37
  """Get if exists."""
40
38
  return os.path.exists(self.path)
41
39
 
42
- @property
43
- def contents(self) -> Optional[str]:
44
- """Get contents."""
45
- if not self.exists:
40
+ def decrypt(self) -> Optional[str]:
41
+ """Decrypt file."""
42
+ if not self._exists or not self.encryption_properties:
46
43
  return None
47
44
 
48
- if not self.encryption_properties:
49
- with open(self.path, "r") as f:
50
- return f.read()
51
-
52
45
  try:
53
46
  return decrypt_file(self.encryption_properties, self.path)
54
47
  except DecryptionError as e:
@@ -97,8 +90,8 @@ class DestinationFileReplacement:
97
90
  """Get contents."""
98
91
  if self._contents != "" and not self._contents.endswith(
99
92
  "\n"
100
- ): # Some programs require newline to consider last line completed
101
- raise ValueError
93
+ ): # Some programs require EOL
94
+ self._contents += "\n"
102
95
 
103
96
  if not self.default_comment_character:
104
97
  return self._contents
@@ -130,57 +123,35 @@ class DestinationFileReplacement:
130
123
  with open(path, open_mode) as f:
131
124
  f.write(contents)
132
125
 
133
- @property
134
- def changed(self) -> bool:
135
- """Get if destination file will change."""
136
- if not self.destination_file.exists:
137
- return True
126
+ def add_to_queue(self) -> None:
127
+ """Add items for replacement to queue."""
128
+ add_copy_item = True
138
129
 
139
- return self.destination_file.contents != self.contents
130
+ decrypted_contents = self.destination_file.decrypt()
140
131
 
141
- @property
142
- def differences(self) -> List[str]:
143
- """Get differences with destination file.
132
+ # If encrypted, only add CopyItem when unencrypted contents changed.
133
+ # CopyItem does not account for encryption, so without this check the
134
+ # file would always be copied.
144
135
 
145
- No differences are returned when contents is not string.
146
- """
147
- results = []
148
-
149
- for line in difflib.unified_diff(
150
- (
151
- self.destination_file.contents.splitlines()
152
- if self.destination_file.contents
153
- else []
154
- ),
155
- self.contents.splitlines(),
156
- fromfile=self.tmp_path,
157
- tofile=self.destination_file.path,
158
- lineterm="",
159
- n=0,
160
- ):
161
- results.append(line)
136
+ if decrypted_contents:
137
+ add_copy_item = decrypted_contents != self.contents
162
138
 
163
- return results
139
+ # Copy and unlink instead of move. MoveItem copies metadata (which
140
+ # means mode etc. of destination file is incorrect, as set to the tmp
141
+ # file until corrected by later queue items). CopyItem does not copy
142
+ # metadata, so if the destination file already exists, its mode etc.
143
+ # is unchanged.
164
144
 
165
- def add_to_queue(self) -> None:
166
- """Add items for replacement to queue."""
167
- if self.changed:
168
- # Copy when changed and always unlink, instead of move when changed
169
- # and unlink when changed. MoveItem copies metadata (which means
170
- # mode etc. of destination file is incorrect, as set to the tmp file
171
- # until corrected by later queue items). CopyItem does not copy
172
- # metadata, so if the destination file already exists, its mode
173
- # etc. is unchanged.
174
-
175
- self.queue.add(
176
- CopyItem(
177
- source=self.tmp_path,
178
- destination=self.destination_file.path,
179
- reference=self.reference,
180
- ),
145
+ if add_copy_item:
146
+ copy_item = CopyItem(
147
+ source=self.tmp_path,
148
+ destination=self.destination_file.path,
149
+ reference=self.reference,
181
150
  )
182
151
 
183
- if self.command:
152
+ self.queue.add(copy_item)
153
+
154
+ if self.command and copy_item.outcomes:
184
155
  self.queue.add(
185
156
  CommandItem(command=self.command, reference=self.reference),
186
157
  )
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: python3-cyberfusion-file-support
3
- Version: 1.3
3
+ Version: 1.5
4
4
  Summary: Library for idempotent writing to files.
5
5
  Author-email: Cyberfusion <support@cyberfusion.io>
6
6
  Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-file-support
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: python3-cyberfusion-common~=2.0
9
- Requires-Dist: python3-cyberfusion-queue-support~=1.3
9
+ Requires-Dist: python3-cyberfusion-queue-support~=1.7.0
10
10
 
11
11
  # python3-cyberfusion-file-support
12
12
 
@@ -0,0 +1,2 @@
1
+ python3-cyberfusion-common~=2.0
2
+ python3-cyberfusion-queue-support~=1.7.0
@@ -1,2 +0,0 @@
1
- python3-cyberfusion-common~=2.0
2
- python3-cyberfusion-queue-support~=1.3