Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repos: improved parsing of the 'series' file #98

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions kas/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,21 @@ async def apply_patches_async(self):
elif os.path.isdir(path) \
and os.path.isfile(os.path.join(path, 'series')):
with open(os.path.join(path, 'series')) as f:
ln = 0
for line in f:
if line.startswith('#'):
ln += 1
if not line.rstrip('\n') or line.startswith('#'):
Copy link
Author

@lejcik lejcik Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condition with rstrip('\n') accepts empty lines \n, but not any whitespace on the line, e.g. \n

continue
p = os.path.join(path, line.split(' #')[0].rstrip())
pn = line.split(' #')[0].rstrip()
if not pn:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle error if patch name pn is parsed as empty string

logging.error('Could not parse patch file name from a \'series\' file. '
'(file: %s, line: %d, repo: %s, patch entry: %s)',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if the error message is clear enough, or should it be rephrased?

os.path.join(path, 'series'),
ln,
self.name,
patch['id'])
return 1
p = os.path.join(path, pn)
if os.path.isfile(p):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line behaves strange on my linux with python ver. 3.10.7,

if pn contains space at the beginning (e.g. 001.patch), isfile() says that such path p exists, and error appears later when patch is about to be applied,

my_patches.append((p, patch['id']))
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_patch/patches/hello/quilt/series
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# test comment

# this is a revert of the other 001 we applied without quilt
001.patch # first patch
002.patch
003.patch # introduce an executable
003.patch # introduce an executable
3 changes: 2 additions & 1 deletion tests/test_patch/patches/kas/quilt/series
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# test comment

# this is a revert of the other 001 we applied without quilt
001.patch # first patch
002.patch
003.patch # introduce an executable
003.patch # introduce an executable