petterreinholdtsen / battery-stats

Log battery charge (battery-stats-collector), show gnuplot graphs (battery-graph)
GNU General Public License v2.0
27 stars 13 forks source link

Use proper default in python grapher #7

Closed anarcat closed 8 years ago

anarcat commented 8 years ago

in the hope to make this script more standard, follow the convention of loading the file automatically

this also supports compression, so those logs can be rotated. i also did a little style cleanup while i was there.

petterreinholdtsen commented 8 years ago

Look good, but will this keep the ability to read the log file from stdin too? I use it during debugging. :)

petterreinholdtsen commented 8 years ago

Another thing: If the default is good, the desktop file can be changed to drop the file argument.

anarcat commented 8 years ago

you may want to check the fileinput module documentation. basically, it supports multiple files, compressed files and - for stdin.

so:

  1. the default is good: it will look at the given glob('/var/log/battery-stats.csv*')
  2. by default, it behaves as if battery-log was called (or in other words, like the default battery-graph), so the desktop file can indeed drop the argument
  3. fileinput also supports using - to parse stdin, and supports gzip files

so i guess i should just add another patch to fix the desktop file here?

anarcat commented 8 years ago

so i rebased the branch and added a few more changes, including the desktop file change, hopefully that's good enough now!

petterreinholdtsen commented 8 years ago

Hm, after pulling these changes, the program do not work for me. :(

% src/battery-stats-graph /var/log/hjemmenett-battery-status.log Traceback (most recent call last): File "src/battery-stats-graph", line 44, in logfiles = fileinput.input(glob.glob(args.logfile), openhook=fileinput.hook_compressed) File "/usr/lib/python2.7/glob.py", line 27, in glob return list(iglob(pathname)) File "/usr/lib/python2.7/glob.py", line 38, in iglob dirname, basename = os.path.split(pathname) File "/usr/lib/python2.7/posixpath.py", line 92, in split i = p.rfind('/') + 1 AttributeError: 'list' object has no attribute 'rfind' % src/battery-stats-graph loading CSV file /var/log/battery-stats.csv* with builtin CSV module building data array guessing expiry /usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py:587: RankWarning: Polyfit may be poorly conditioned warnings.warn(msg, RankWarning) this battery will reach end of life (5%) in -7943 days, 10:15:41.964910, on 1994-06-27 03:46:55.108877 building graph Traceback (most recent call last): File "src/battery-stats-graph", line 200, in render_graph() File "src/battery-stats-graph", line 158, in render_graph if sys.stdout.isatty() and args.outfile == sys.stdout: AttributeError: 'Namespace' object has no attribute 'outfile' %

I'm running on Debian Jessie.

anarcat commented 8 years ago

right, sorry about that - fixed in #11.