7 days into learning PYTHON & looking for some feedback
Hey folks. Title says it all, but... It's been an interesting few days. Never done anything object-oriented before. Previously only had BASH experience. I'm LOVING python. I see so much potential (of course). Can't wait to really get a feel for what's available in the Standard Library.
I have no programmer friends. Actually -- scratch that; I don't even have any *nix friends. So it would be lovely to get some external feedback on my first real python script, so I can nip any bad habits in the bud right now.
#!/usr/bin/env python
# a4crypt v0.5.2 last mod 2011/12/17
# Latest version at <http://github.com/ryran/a7crypt>
# Copyright 2011 Ryan Sawhill <ryan@b19.org>
#
# 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 the GNU
# General Public License <gnu.org/licenses/gpl.html> for more details.
#------------------------------------------------------------------------------
# TODO: SCRIPT docstring; chop all print() lines down to 79w
# TODO: Implement GPG reading passphrase from fd instead of tempfile with
# --passphrase-fd or --command-fd (will have to also make data use that method)
# Standard Library stuff only
from os.path import exists
from collections import namedtuple
from getpass import getpass
from tempfile import NamedTemporaryFile
from subprocess import Popen, PIPE, STDOUT
class a4crypt:
"""Provide cmdline wrapper for symmetric {en,de}cryption functions of GPG.
This simply aims to make GPG1/GPG2 symmetric ASCII encryption in terminals
easier and more fun. (Actually, this was just an excuse for a project in my
first week of learning python, but hey. ...)
Instantiate this class with color=False if you like spam.
The most important method here is main() -- it will launch an interactive
prompt and take care of everything for you. That said, you can set the
proper attribute or two and launch the processing method yourself. ...
And that method would be launch_gpg() which does the actual encryption &
decryption. To use it directly, first save your input to self.inputdata
(simple text or file-objects welcome; lists are not), then run:
launch_gpg(mode, passfile)
where mode is either e or d and passfile is the path to a file containing
only your passphrase.
It would of course be simpler and more secure to just let main() do that
for you, since it would save the passphrase to a tempfile only readable by
you, and would delete it as soon as the encryption or decryption is done,
usually only seconds after the file was created. ... But suit yourself.
"""
def __init__(self, color=True):
"""Define vars we need, incl. colors. Check for GPG or GPG2."""
self.inputdata = ''
Colors = namedtuple('Colors', 'RST BLD R B G C')
if color:
self.c = Colors(
RST='\033[0m', BLD='\033[0m\033[1m', R='\033[1;31m',
B='\033[1;34m', G='\033[1;32m', C='\033[0;36m')
else:
self.c = Colors('', '', '', '', '', '')
.......
TRIMMED. For the rest, see https://github.com/ryran/a7crypt/blob/master/a4crypt.py
Last edited by ryran; 12-17-2011 at 07:07 AM..
Reason: updated to v0.5.2
I'm new to Unix. I'm just looking for really good unix documents through Internet as pdf format on programming in all shells, and system adminstrator documents, and well as just all around really good documents on unix.
Thank you (5 Replies)
Hi,
I am harsath , am new to UNIX- Aix ust started to learning , interested in working with servers , is it necessary to know shell scripting before learning aix, will i get job only if i know aix ....
pls reply..... Thanks in advance.... (2 Replies)
Hello All
My Questions About Which Unix & Linux Certifications Names In This Days ?
I Mean Red Hat Certifications , Solaris Certifications , IBM Certifications , HP Certifications and BSD Certifications
just i need the names of these Certifications and How can i enter to Certifications... (1 Reply)
I am planning on taking a class in Python. My choices are 2.5 or 3.0. Which version should I choose? I am getting the impression they are two separate paths.
thanks. (5 Replies)
Hello!
For a couple of years I'm developing an IT infrastructure monitoring system in the research group in my university. And now we would like to use some nontrivial methods in this area.
So, I decided to contact with experienced users on the subject. My questions would be:
Do existing... (3 Replies)
Hi guys,
I am currently working as a system administration engineer, administering telecom applications on linux/unix platforms.
I want to learn new things and improve the ones that i have and for this i though to really work on some project or something but i lack of ideas.
I want to be... (2 Replies)
Hi there,
im just having a hard time understanding why this code does not print anything that is suppose to print:
score = raw_input ('what is your score? \n')
try:
if 1.0 == float(score) >= 0.9:
print "A"
elif 0.9 > float(score) >= 0.8:
... (1 Reply)