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

Handling situations where project file section missing. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 9 additions & 6 deletions pysock/sorterer/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ def find_start_and_end_line_indexes(self, lines):
line_index += 1

def feed_records(self, lines):
line_index = self.start_line_index + 1

while (line_index < self.end_line_index):
record = Record(lines, line_index)
self.records.append(record)
line_index += len(record.property_lines)
if self.start_line_index is None:
AssertionError('Section %s does not contain starting line index.' % self.key)
else:
line_index = self.start_line_index + 1

while (line_index < self.end_line_index):
record = Record(lines, line_index)
self.records.append(record)
line_index += len(record.property_lines)


28 changes: 14 additions & 14 deletions pysock/sorterer/sorterer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ def sort_lines_in_section(section_key, lines):
section = Section(key=section_key, lines=lines)

if section.start_line_index is None or section.end_line_index is None:
AssertionError('Section %s does not contain starting or ending line index.' % section_key)

section.records.sort(key=lambda x: x.name, reverse=False)

for record in section.records:
for line in record.property_lines:
del lines[section.start_line_index + 1]

line_index = section.start_line_index + 1
for record in section.records:
sort_deep_records_in_record(record)
for line in record.property_lines:
lines.insert(line_index, line)
line_index += 1
AssertionError('Section %s does not contain starting or ending line index.' % section_key)
else:
section.records.sort(key=lambda x: x.name, reverse=False)

for record in section.records:
for line in record.property_lines:
del lines[section.start_line_index + 1]

line_index = section.start_line_index + 1
for record in section.records:
sort_deep_records_in_record(record)
for line in record.property_lines:
lines.insert(line_index, line)
line_index += 1


def sort_deep_records_in_record(record):
Expand Down