[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Re: installing an end user editable file

Thanks very much Lars,

That's massively helpful, it clarifies a lot of stuff, I reckon I
should be able to get this package working properly now, phew! - I
knew making your first Debian package had a reputation for taking a
few attempts, but I wasn't quite ready for this!



On 14 February 2011 21:28, Lars Buitinck <larsmans@gmail.com> wrote:
> 2011/2/14 james frize <jamesfrize@gmail.com>:
>> Hey mentors,
> I'm not a mentor, I just lurk on this list to learn.
>> I like the idea of having a default copy of the file used by my
>> program, as suggested by Lars and PJ, so I've altered my source code
>> to use a default file and allow multiple users to have their own
>> copies of this file in their home/<user>/Documents folder.
>> "creating a default file in /usr/share and having the program copy it
>> to the user's directory when it's run"
>> However, I can't open a file from /usr/share via my python script as I
>> don't have permission to open files in a protected directory, and
>> after reading up a bit on it, it's been suggested that it's bad form
>> to invoke super user in a script, as it's construed as a security risk
>> (i.e. http://tldp.org/HOWTO/Security-HOWTO/file-security.html;
>> http://www.velocityreviews.com/forums/t346075-sudo-open-python-newbee-question.html)
>> Do I really have to use sudo or super user privileges to just open and
>> copy a text template?
> Not at all. I was thinking along the lines of:
> def homedir():
>    '''Get current user's homedir'''
>   home = os.getenv('HOME')
>   if home == None:
>      raise IOError('cannot copy links.txt: HOME not set')
>   return home
> def open_links_txt():
>   '''Open links.txt; install for current user if necessary'''
>   # http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
>   datadir = os.getenv('XDG_DATA_HOME')
>   if datadir == None:
>      datadir = os.path.join(homedir(), '.local', 'share')
>   links_txt = os.path.join(datadir, 'links.txt')
>   if not os.path.exists(links_txt):
>      shutil.copy('/usr/share/gtk-link-lizard/links.txt', links_txt)
>   return open(links_txt)
> Notes:
> * UNTESTED CODE, may contain the stupidest of syntax errors or worse
> * contains a race condition due to the use of os.path.exists, but that
> shoudn't matter unless the user sets XDG_DATA_HOME to the wrong value
> or has a world-writable homedir (in which case s/he's doomed anyway)
> * I know this doesn't fit the original app particularly well, so
> please integrate with existing code.
>> Where do packagers normally install files of this type?
> I put it in /usr/share/gtk-link-lizard for the purpose of the example.
> I don't know the Debian packaging rules by heart, but /usr/share/doc
> seems to be the wrong place; that's for documentation. It should be
> safe to remove documentation (sudo rm -rf /usr/share/doc) without
> applications suddenly starting to malfunction.
>> I thought it might be a good idea to store it in
>> home/<user>/.<packageName> But I'm still at a loss as to how I can
>> find a users home directory from the rules makefile :(
>> been trying to use ~/ and $XDG_CONFIG_HOME but I just end up with
>> everything being installed in folders called "~" or "DG_CONFIG_HOME"
> DON'T. Users' homedirs are off limits to package managers such as
> dpkg. The application, when run, may install a file there, but the
> rules script should not.
> Regards,
> Lars

Reply to: