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

feat: auto cut the overflow lines and keep only the first 1500 lines (30 pages) and the last 1500 lines (last 30 pages) as per the regulation #4

Open
wants to merge 3 commits 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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ If you want to strictly meet the [regulation](./著作权法.md#第十条-软件
python ramile-cli.py extract <path to your project root> Inf
```

And then you just have to open it and keep the first 30 pages and the last 30 pages, and remove all the intermediate pages.

## Config

Ramile automatically loads the config file `.ramileconfig.json` from the project root, if it exits. The file should be in json format. Possible config items as below:
Expand Down
43 changes: 36 additions & 7 deletions ramile/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Project(object):
info = None
output = True
files = []
lines = []

def __init__(self, project_root, lines_to_extract=3000, output_file='extracted_code.docx', output=True):
self.info = ProjectInfo(project_root, lines_to_extract)
Expand Down Expand Up @@ -44,8 +45,9 @@ def run(self, output=True, echo=True):
if self.info.has_extracted_enough_lines():
break
# self.output_file.close()
print('current file = ', __file__)
self.output_file.save(self.output_path)

self.write_to_file()

if echo:
self.print_summary()

Expand All @@ -62,18 +64,45 @@ def print_summary(self):
print("%s : %s lines" % (file.file_path, file.extracted_lines))
print("Code was extracted in: %s" % self.output_path)
print("Total extracted: %s lines" % self.info.lines_extracted)
print("Wrote to file: %s lines" % len(self.lines))
print("Total skipped comments: %s lines" %
self.info.lines_skipped_comments)
print("Total skipped blank lines: %s lines" %
self.info.lines_skipped_blank)
if self.info.lines_extracted > 3000:
print("Total skipped overflow lines: %s lines" %
(self.info.lines_extracted - len(self.lines)))

def export(self, line):
max_length_of_line = 60
appended = 0

while appended < len(line):
l = line[appended:appended+max_length_of_line]
self.lines.append(l)
self.info.lines_extracted += 1
appended += len(l)

return

def write_to_file(self):
if self.output:
# self.output_file.write(line)
# if not line.endswith('\n'):
# self.output_file.write('\n')
if self.paragraph is None:
self.paragraph = self.output_file.paragraphs[0]
self.paragraph.add_run(line)
self.info.lines_extracted += 1

if self.info.lines_extracted > 3000:
lines_to_cut = self.info.lines_extracted - 3000
del self.lines[1501:1501+lines_to_cut]

i = 0
for line in self.lines:
i += 1
if i < 3000 and not line.endswith('\n'):
line += '\n'
if i == 3000 and line.endswith('\n'):
line = line[0:len(line)-1]

self.paragraph.add_run(line)

self.output_file.save(self.output_path)
return
1 change: 1 addition & 0 deletions ramile/project_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProjectInfo(object):
lines_extracted = 0
lines_skipped_comments = 0
lines_skipped_blank = 0
lines_skipped_overflow = 0
ignore = []
filters = []

Expand Down