7 days into learning PYTHON & looking for some feedback


 
Thread Tools Search this Thread
Top Forums Programming 7 days into learning PYTHON & looking for some feedback
# 1  
Old 12-15-2011
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.

Pretty colorized view of code here: https://github.com/ryran/a7crypt/blob/master/a4crypt.py

Thanks for reading!

Code:
#!/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
# 2  
Old 12-15-2011
Greetings,
This little post to say ho much I am pleased to see something different, at last a user wishing to share with his peers. I would encourage you to continue this way, unfortunately I don't have time to look at and learn Python (now anyway...) and so I cannot make any comments... perhaps next time in shell (ksh...)?

All the best
# 3  
Old 12-15-2011
Regards vbe. Smilie
# 4  
Old 12-15-2011
Quote:
I don't even have any *nix friends.
You have one now Smilie
# 5  
Old 12-15-2011
Thanks for the kind words. Despite this being the first post where I wasn't answering someone else's question, a part of me was a little worried I would get misunderstood and flamed for linking. In any case, looks like I need to find some python forums.
# 6  
Old 12-16-2011
Maybe no python geek at the moment... but click on the above python tag and see there are quite some python stuff here, question of patience... Nice clean code you wrote now I took the time to read...
# 7  
Old 12-16-2011
i am also interested in learning a OOP language?? am learning c++ right now .i heard python is a great language and looking forward to learning it as well..thanx for posting SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Learning python, lost with script

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)
Discussion started by: la2015
1 Replies

2. Shell Programming and Scripting

Learning project ideas - shell, python, UNIX tools, system administration

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)
Discussion started by: capitanui
2 Replies

3. Infrastructure Monitoring

Event processing & machine learning in monitoring system

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)
Discussion started by: pyalxx
3 Replies

4. Programming

General question about learning Python

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)
Discussion started by: djehresmann
5 Replies

5. UNIX for Dummies Questions & Answers

Which Unix & Linux Certifications Names In This Days ??

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)
Discussion started by: Eng/G.Mohammad
1 Replies

6. AIX

LEARNING AIX - PLS GUID MY BRO 'S & SISTERS !

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)
Discussion started by: harsath24330
2 Replies

7. Shell Programming and Scripting

how to increment days according to year & month

Hiii i have a file with data as shown below: a.dat: RAO 1900 2 7 0 0 0.00 10.8000 76.8000 10.0 0 0.00 0 6.00 0.00 0.00 0 0.00 6.00 0 NULL LEE 1901 2 15 0 0 0.00 26.0000 100.0000 0.0 0 0.00 0 0.00 0.00 0.00 0 6.00 6.00 0 NULL RAO 1901 4... (3 Replies)
Discussion started by: reva
3 Replies

8. UNIX for Advanced & Expert Users

how to archive logs older than 5 days & then delete them?

My code is tar -cvf logs.tar `find /usr/openv/logs/512*.log -mtime +2` && find *.log* -mtime +2 -exec rm {} \; this gives me output as: tar: Missing filenames:confused: (1 Reply)
Discussion started by: timus1980
1 Replies

9. UNIX for Dummies Questions & Answers

Learning Unix & Linux

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)
Discussion started by: faaarin
5 Replies
Login or Register to Ask a Question