Re: Share Code: Laptop Lid State

2013-12-05 Thread Adam Tauno Williams
On Tue, 2013-07-30 at 17:00 +0100, Chris Angelico wrote: 
 On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
 devyncjohn...@gmail.com wrote:
  Aloha everyone!
 I attached a script that I thought I could share with everyone for your
  help. This Python3 script only works on Unix systems. It prints the current
  state of the lid. This can be used to make a script that performs some
  action when the lid is closed or open. The script is licensed under LGPLv3
  and I will soon upload it to my Launchpad account. Enjoy!
 There's... no Python code in that. Why not simply
 open(/proc/acpi/button/lid/LID/state) and read from it, instead of
 using cat and awk?

The correct way to implement this is to use the power management
services available on the System D-Bus.

Integrating with D-Bus from Python is easy!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Share Code: Laptop Lid State

2013-07-31 Thread Chris Angelico
On Wed, Jul 31, 2013 at 4:05 AM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

 On 07/30/2013 12:00 PM, Chris Angelico wrote:

 On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
 devyncjohn...@gmail.com wrote:

 Aloha everyone!

 I attached a script that I thought I could share with everyone for
 your
 help. This Python3 script only works on Unix systems. It prints the
 current
 state of the lid. This can be used to make a script that performs some
 action when the lid is closed or open. The script is licensed under
 LGPLv3
 and I will soon upload it to my Launchpad account. Enjoy!

 There's... no Python code in that. Why not simply
 open(/proc/acpi/button/lid/LID/state) and read from it, instead of
 using cat and awk?

 ChrisA

 The script returns either open or close instead of printing the whole
 file contents. I thought some people would find it useful (^_^;).

Not having a Linux laptop handy I can't test it, but my point is that
text parsing of that nature can be done directly by Python. You can
snip out the open or close easily with one, maybe two lines of
code at the most, and that without dropping to a shell, a completely
superfluous 'cat' process, and awk. You then capture the STDOUT of
that and promptly print it to your own STDOUT. Why not either do it
truly in Python, or do it directly in a shell script and skip the
Python interpreter?

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Share Code: Laptop Lid State

2013-07-30 Thread Devyn Collier Johnson

Aloha everyone!

   I attached a script that I thought I could share with everyone for 
your help. This Python3 script only works on Unix systems. It prints the 
current state of the lid. This can be used to make a script that 
performs some action when the lid is closed or open. The script is 
licensed under LGPLv3 and I will soon upload it to my Launchpad account. 
Enjoy!


Mahalo,

devyncjohn...@gmail.com
#!/usr/bin/env python3
#Made by Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS 
devyncjohn...@gmail.com

#   LGPLv3 - 2013. (Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS)©
#This program is free software: you can redistribute it and/or modify it under 
the terms of the GNU General Public License as
#published by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.
#   This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU 
General Public License for more details.
#You should have received a copy of the GNU General Public License along with 
this program. If not, see http://www.gnu.org/licenses/.

import subprocess; print(subprocess.getoutput('cat 
/proc/acpi/button/lid/LID/state | awk \'{ print $2 }\''))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code: Laptop Lid State

2013-07-30 Thread Chris Angelico
On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:
 Aloha everyone!

I attached a script that I thought I could share with everyone for your
 help. This Python3 script only works on Unix systems. It prints the current
 state of the lid. This can be used to make a script that performs some
 action when the lid is closed or open. The script is licensed under LGPLv3
 and I will soon upload it to my Launchpad account. Enjoy!

There's... no Python code in that. Why not simply
open(/proc/acpi/button/lid/LID/state) and read from it, instead of
using cat and awk?

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code: Laptop Lid State

2013-07-30 Thread Ian Kelly
On Jul 30, 2013 10:06 AM, Chris Angelico ros...@gmail.com wrote:

 On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
 devyncjohn...@gmail.com wrote:
  Aloha everyone!
 
 I attached a script that I thought I could share with everyone for
your
  help. This Python3 script only works on Unix systems. It prints the
current
  state of the lid. This can be used to make a script that performs some
  action when the lid is closed or open. The script is licensed under
LGPLv3
  and I will soon upload it to my Launchpad account. Enjoy!

 There's... no Python code in that. Why not simply
 open(/proc/acpi/button/lid/LID/state) and read from it, instead of
 using cat and awk?

Or for that matter, why not just make it a bash script instead of Python?
It's kind of pointless to go to all the trouble of starting a Python
interpreter just to have it start a subprocess.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Share Code: Laptop Lid State

2013-07-30 Thread Devyn Collier Johnson


On 07/30/2013 12:00 PM, Chris Angelico wrote:

On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
devyncjohn...@gmail.com wrote:

Aloha everyone!

I attached a script that I thought I could share with everyone for your
help. This Python3 script only works on Unix systems. It prints the current
state of the lid. This can be used to make a script that performs some
action when the lid is closed or open. The script is licensed under LGPLv3
and I will soon upload it to my Launchpad account. Enjoy!

There's... no Python code in that. Why not simply
open(/proc/acpi/button/lid/LID/state) and read from it, instead of
using cat and awk?

ChrisA
The script returns either open or close instead of printing the 
whole file contents. I thought some people would find it useful (^_^;).


DCJ
--
http://mail.python.org/mailman/listinfo/python-list