licenses / lice

Generate license files for your projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

existing file

alex179ohm opened this issue · comments

@Yonaba
Though, i am willing to add something on the top of it. In case the file to be generated already exists, it will be opened, license will be appended as an header and then file will be saved.

At this moment lice have this future, in default mode open the file in read/binary mode append a license as a header and save/close it.
We can add a --force argument and add a answer before lice write the file which is showed only if the file already exist.
something like:

$ lice -f test.py
do you want write <license> license in test.py?[Y/n]

and with --force:

$ ls
test.py
$ lice -f test.py --force

Okay then.
Actually, i already committed the same feature in lice-lua (but didn't pushed yet). The relevant option was named --noclear (by default, it clears the output file when found existing.

but does it clear only a previous license or the entire content of the file?

It is only supposed to clear the license header. Though i haven't got rid of all the bugs (yet), it still fails in some cases. Still working on it.
Is that the case already for the python implementation ?

open file in append mode. ( write mode erase the content of the file in lua).
something like this:

f = io.open("test.txt", "a")
f:seek("set") -- at the beginning of the file
f:write(comment[lang][0] .. '\n')
f:write(comment[lang][1] .. ' ' .. licenseline .. '\n')
f:write(comment[lang][2] .. '\n')
f:close()

take it like pseudo code.
(but I tested it now and it work fine. (lua 5.2.1))

I may have stated my point incorrectly. My bad.
Actually, there is no problem on appending a header into a file from Lua.
I am quite familiar with those file writing/saving operations.
When the license file already exists, and already has an header written by lice on a previous operation, the ideal thing would be opening this file, detect the old header, and strictly replace it, while preserving the contents of the file (source code, for instance).
That is what i am trying to do (with the Lua port). I was wondering actually if the original python version already behaves that way.

PS: very interesting discussion, indeed. :)

Sorry I didn't understand.
No, In python I didn't implemented this future.
The main problem to implement this future is know what kind of license the file contain.
It's necessary a metadata (something like a marker in license file) or you have to compare a large part of license files with the opened file to know exactly how many lines are needed to be erased.

maybe we can introduce a file for information and configuration stuffs.
but the idea is not a bad idea.

Yes, implementing this (roughly) would be quite complicated. But making some reasonable assumptions would help making it easier.
We can consider that the user is willing to generate license file (and headers) with lice, and lice-only. Starting from that, when appending a license as header to a source code file or when generating the file, we can think of a general pattern using specific string markers so that we can easily recognize the license header when parsing the source file from code.
Of course, all those would become irrelevant when there is no output file specified, or when the output file does not require a specific formating (text style).
It would be nice if one can generate a source file with an header , and then switch to another license still using lice without compromising the source code integrity! 👍

I like a feature that will prepended a license header to the file, but replacing existing license headers makes me nervous. There is plenty of source code out there that starts with a comment block that ISN'T a license header. I don't really want to have to be so good at detecting them that we wouldn't accidentally remove non-license header comment blocks. So for

$ lice -f test.py

If test.py doesn't exist, it is created with the header. If test.py does exist, the header is prepended to the beginning of the file.

@jcarbaugh (says): There is plenty of source code out there that starts with a comment block that ISN'T a license header.
Good point. And it might not be wise to enforce people adopt a specific formatting style.

@jcarbaugh (says): So for $ lice -f test.py, if test.py doesn't exist, it is created with the header. If test.py does exist, the header is prepended to the beginning of the file.
Okay, I think I can accomodate with this, and take it as basis for the Lua implementation.

PS: And oh, @alex179ohm, I think this can be closed now. 👍