[DMC-883] gfal-ls fails when trying to evaluate the LS_COLORS envvar Created: 09/Sep/16  Updated: 06/Feb/17  Resolved: 12/Sep/16

Status: Closed
Project: DMC - Development
Component/s: None
Affects Version/s: gfal2-util 1.4
Fix Version/s: gfal2-util 1.5.0
Security Level: Public Data (This ticket is visible to anyone on the internet and will be indexed by search engines)

Type: Bug Priority: Minor
Reporter: Oliver Keeble Assignee: Alejandro Alvarez Ayllon
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Component Watchers:

 Description   

From RQF0638850;

Hi all,

one of our users encountered a problem with gfal-ls, which failed when
trying to evaluate the LS_COLORS envvar [1].

Apparently the user had been sourcing a somewhat malformed file
coloring scheme [2]
~~> *.com has only been set to bold without any further coloring and
had not been separated from *.tar by a ':' – apparently, bash/zsh have
been skipping that without complaints.

Probably the fastest thing would be a "try: typ, color =
entry.split('=') except: pass" and drop the coloring if the env is broken?

Cheers,
Thomas

[1]
Traceback (most recent call last):
File "/usr/bin/gfal-ls", line 24, in <module>
from gfal2_util.shell import Gfal2Shell
File "/usr/lib/python2.6/site-packages/gfal2_util/shell.py", line 25, in
<module>
import ls # @UnusedImport
File "/usr/lib/python2.6/site-packages/gfal2_util/ls.py", line 63, in
<module>
typ, color = entry.split('=')
ValueError: too many values to unpack

[2]
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:.cmd=01;32:.exe=01;32:.com=01;.tar=01;33:.tgz=01;33:.arj=01;33:.taz=01;33:.lzh=01;33:.zip=01;33:.z=01;33:.Z=01;38:.gz=01;38:.deb=01;38:.jpg=01;38:.gif=01;38:.bmp=01;38:.ppm=01;38:.tga=01;38:.xbm=01;38:.xpm=01;38:.tif=01;38:.mpg=01;37:.avi=01;37:.gl=01;37:*.dl=01;37:

[3]
> gfal2_util/ls.py
color_dict = dict()
color_env = os.environ.get('LS_COLORS', None)
if color_env:
for entry in [entry for entry in color_env.split(':') if '=' in entry]:
typ, color = entry.split('=')
color_dict[typ] = color



 Comments   
Comment by Alejandro Alvarez Ayllon [ 12/Sep/16 ]

ls actually warns about the invalid value

# ls
ls: unparsable value for LS_COLORS environment variable

I'd say it would be nice for gfal2-util to do it too.

Comment by GitLab service [ 12/Sep/16 ]

Alejandro Alvarez Ayllon mentioned this issue in a commit of dmc/gfal2-util:
'DMC-883: Warning if LS_COLORS can't be parsed'

Comment by Clockwork Droid [ 12/Sep/16 ]

SUCCESS: Integrated in Jenkins build (devel) gfal2-util #47 (See https://jenkins.cern.ch/fts-dmc/job/(devel)%20gfal2-util/47/)
DMC-883: Warning if LS_COLORS can't be parsed (alejandro.alvarez.ayllon: rev 75c448dc9cdfd6f1b1b3b46a8182bb39692002a6)

Comment by GitLab service [ 06/Feb/17 ]

Alejandro Alvarez Ayllon mentioned this issue in a commit of dmc/gfal2-util:
'DMC-883: Warning if LS_COLORS can't be parsed'

Generated at Mon Aug 21 21:25:13 CEST 2017 using JIRA 7.3.8#73019-sha1:94e8771b8094eef96c119ec22b8e8868d286fa88.