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

Support for multiple files - input as a file list - using -f flag #21

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions Code2pdf/code2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def parse_arg():
type=str,
default="default",
metavar="NAME")
parser.add_argument(
"-f",
"--filelist",
help="filename contains list of files to be converted",
action="store_true")
parser.add_argument(
"-v",
"--version",
Expand All @@ -142,9 +147,19 @@ def parse_arg():

def main():
args = parse_arg()
pdf_file = get_output_file(args.filename, args.outputfile)
pdf = Code2pdf(args.filename, pdf_file, args.size)
pdf.init_print(linenos=args.linenos, style=args.style)
if (args.filelist == False):
pdf_file = get_output_file(args.filename, args.outputfile)
pdf = Code2pdf(args.filename, pdf_file, args.size)
pdf.init_print(linenos=args.linenos, style=args.style)
else:
Copy link
Owner

Choose a reason for hiding this comment

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

@cibinjoseph Hi! Can we add a test suite for your changes before we merge? Also, update the usage/argparser instructions accordingly. Thanks! :)

Copy link
Author

Choose a reason for hiding this comment

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

(On the test suite) Sure! How do you wanna go about it?
And I had already updated the argparser instructions in the commit.

Copy link
Author

Choose a reason for hiding this comment

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

I'll edit the 'usage' section in a while!

Copy link
Owner

Choose a reason for hiding this comment

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

@cibinjoseph You may find some test suit written under tests/test.py. You may add yours there as well.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, got it!

with open(args.filename) as filelist:
Copy link
Owner

Choose a reason for hiding this comment

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

@cibinjoseph I doubt here with open would work this way. It expects a string or buffer and not a list. Even if type of filename is not a list but a string, you may still want to split the filenames and feed to open separately.

Anyway, that's why I asked for a test suite. :)

Copy link
Author

Choose a reason for hiding this comment

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

It seems to work for me.
open(args.filename) as filelist: opens the file that contains the list of file names.
The next line filenames=filelist.read().splitlines() would parse filelist for the names of the files and then store it as a list in filenames.

And yes, I did want to finish the test suite but got caught up with some work. Don't accept without the test suite! :D

Copy link
Author

Choose a reason for hiding this comment

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

I remember getting a segmentation fault from PyQT after the program run (for the copy in your repo too). That seemed to deter me from working on the test suite. Have to check if it still exists when PyQT is compiled from scratch.

Copy link
Owner

Choose a reason for hiding this comment

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

@cibinjoseph Cool! I misunderstood filename being comma separated list of file names passed as a console arg. :)

Please feel free to look into the seg fault issue as I've not been able to investigate myself due to work commitments. I believe there is already an issue created by you for this.
Also, to be consistent, I will go ahead with your current PR once you've added the suite. Thanks!

filenames=filelist.read().splitlines()
for ifile in filenames:
args.filename=ifile
pdf_file = get_output_file(args.filename, args.outputfile)
pdf = Code2pdf(args.filename, pdf_file, args.size)
pdf.init_print(linenos=args.linenos, style=args.style)

return 0

if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ Contributor

`cclauss <https://github.com/cclauss>`__

`Cibin Joseph <https://github.com/cibinjoseph>`__

License
~~~~~~~

.. figure:: https://cloud.githubusercontent.com/assets/7397433/9025904/67008062-3936-11e5-8803-e5b164a0dfc0.png
:alt: gpl
.. _Demo: https://cloud.githubusercontent.com/assets/7397433/10060934/645a3cc6-6272-11e5-9ebb-a1ac24c86d67.gif
.. _Demo: https://cloud.githubusercontent.com/assets/7397433/10060934/645a3cc6-6272-11e5-9ebb-a1ac24c86d67.gif
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Have an idea to make it better? Go ahead! I will be happy to see a pull request

[cclauss](https://github.com/cclauss)

[Cibin Joseph](https://github.com/cibinjoseph)

### License
![gpl](https://cloud.githubusercontent.com/assets/7397433/9025904/67008062-3936-11e5-8803-e5b164a0dfc0.png)

Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ Contributor

`cclauss <https://github.com/cclauss>`__

`Cibin Joseph <https://github.com/cibinjoseph>`__

License
~~~~~~~

Expand Down