Τα πάντα για την Python

...του ubuntu και έργων ΕΛ/ΛΑΚ (Έργα-Οδηγοί-Προτάσεις)

Συντονιστής: konnn

Re: Τα πάντα για την Python

Δημοσίευσηαπό clepto » 01 Ιαν 2012, 21:20

το έχω ήδη κατεβάσει... ;) για αυτό ρώτησα πιο πριν για την Popen
1 Γνώσεις Linux: Ικανοποιητικό ┃ Προγραμματισμού: Ικανοποιητικό ┃ Αγγλικών: Ικανοποιητικό
2 Ubuntu 13.04 raring 3.8.0-30-generic 64bit (en_US.UTF-8, Unity ubuntu), Ubuntu 3.8.0-19-generic, Windows 7
3 Intel Core i7-3537U CPU @ 2.00GHz ‖ RAM 3840 MiB ‖ ASUS K56CB
4 Intel 3rd Gen Core processor Graphics Controller [8086:0166] {i915}
5 wlan0: Atheros Inc. AR9485 Wireless Network Adapter [168c:0032] (rev 01) ⋮ eth0: Realtek RTL8111/8168 PCI Express Gigabit Ethernet controller [10ec:8168] (rev 0a)
clepto
antiwinTUX
antiwinTUX
 
Δημοσιεύσεις: 4102
Εγγραφή: 07 Ιαν 2010, 16:27
Τοποθεσία: Πάτρα
Launchpad: christriant
IRC: Clepto
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό clepto » 01 Ιαν 2012, 21:51

παιδια εδω που εχω λαθος;
Κώδικας: Επιλογή όλων
#!/usr/bin/python

import subprocess

ECHO = "/usr/bin/echo"
ENCFS = "/usr/bin/encfs"
password = "password"
folderdir = "/home/chris/test"
enfolderdir = "/home/chris/.test"

p1 = subprocess.Popen([ECHO, password],\
stdout=subprocess.PIPE)
p2 = subprocess.Popen([ENCFS, "-S", enfolderdir, folderdir], stdin=p1.stdout, stdout=subprocess.PIPE)


Κώδικας: Επιλογή όλων
chris@chris-Aspire-5732Z:~/Προγραμματισμός/PYTHON$ ./pexpect-example2.py
Traceback (most recent call last):
File "./pexpect-example2.py", line 12, in <module>
stdout=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1239, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
1 Γνώσεις Linux: Ικανοποιητικό ┃ Προγραμματισμού: Ικανοποιητικό ┃ Αγγλικών: Ικανοποιητικό
2 Ubuntu 13.04 raring 3.8.0-30-generic 64bit (en_US.UTF-8, Unity ubuntu), Ubuntu 3.8.0-19-generic, Windows 7
3 Intel Core i7-3537U CPU @ 2.00GHz ‖ RAM 3840 MiB ‖ ASUS K56CB
4 Intel 3rd Gen Core processor Graphics Controller [8086:0166] {i915}
5 wlan0: Atheros Inc. AR9485 Wireless Network Adapter [168c:0032] (rev 01) ⋮ eth0: Realtek RTL8111/8168 PCI Express Gigabit Ethernet controller [10ec:8168] (rev 0a)
clepto
antiwinTUX
antiwinTUX
 
Δημοσιεύσεις: 4102
Εγγραφή: 07 Ιαν 2010, 16:27
Τοποθεσία: Πάτρα
Launchpad: christriant
IRC: Clepto
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό Ilias95 » 01 Ιαν 2012, 22:01

@clepto
Κώδικας: Επιλογή όλων
ilias@ilias-pc:~$ which echo
/bin/echo
Ilias95
saintTUX
saintTUX
 
Δημοσιεύσεις: 1548
Εγγραφή: 29 Απρ 2011, 23:26
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό clepto » 01 Ιαν 2012, 22:08

τραγικότατος :P
δουλεύει όπως θα έπρεπε τώρα... ευχαριστώ!
1 Γνώσεις Linux: Ικανοποιητικό ┃ Προγραμματισμού: Ικανοποιητικό ┃ Αγγλικών: Ικανοποιητικό
2 Ubuntu 13.04 raring 3.8.0-30-generic 64bit (en_US.UTF-8, Unity ubuntu), Ubuntu 3.8.0-19-generic, Windows 7
3 Intel Core i7-3537U CPU @ 2.00GHz ‖ RAM 3840 MiB ‖ ASUS K56CB
4 Intel 3rd Gen Core processor Graphics Controller [8086:0166] {i915}
5 wlan0: Atheros Inc. AR9485 Wireless Network Adapter [168c:0032] (rev 01) ⋮ eth0: Realtek RTL8111/8168 PCI Express Gigabit Ethernet controller [10ec:8168] (rev 0a)
clepto
antiwinTUX
antiwinTUX
 
Δημοσιεύσεις: 4102
Εγγραφή: 07 Ιαν 2010, 16:27
Τοποθεσία: Πάτρα
Launchpad: christriant
IRC: Clepto
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό clepto » 01 Ιαν 2012, 23:41

μπορώ να έχω 2 stdin σε μια Popen;
1 Γνώσεις Linux: Ικανοποιητικό ┃ Προγραμματισμού: Ικανοποιητικό ┃ Αγγλικών: Ικανοποιητικό
2 Ubuntu 13.04 raring 3.8.0-30-generic 64bit (en_US.UTF-8, Unity ubuntu), Ubuntu 3.8.0-19-generic, Windows 7
3 Intel Core i7-3537U CPU @ 2.00GHz ‖ RAM 3840 MiB ‖ ASUS K56CB
4 Intel 3rd Gen Core processor Graphics Controller [8086:0166] {i915}
5 wlan0: Atheros Inc. AR9485 Wireless Network Adapter [168c:0032] (rev 01) ⋮ eth0: Realtek RTL8111/8168 PCI Express Gigabit Ethernet controller [10ec:8168] (rev 0a)
clepto
antiwinTUX
antiwinTUX
 
Δημοσιεύσεις: 4102
Εγγραφή: 07 Ιαν 2010, 16:27
Τοποθεσία: Πάτρα
Launchpad: christriant
IRC: Clepto
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό Ilias95 » 01 Ιαν 2012, 23:50

clepto έγραψε:μπορώ να έχω 2 stdin σε μια Popen;

δεν νομίζω. "ένωσε" πρώτα ότι θέλεις να πάρεις σαν είσοδο και πέρασε το μετά.
Ilias95
saintTUX
saintTUX
 
Δημοσιεύσεις: 1548
Εγγραφή: 29 Απρ 2011, 23:26
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό clepto » 02 Ιαν 2012, 01:30

να αλλα οταν σου ζηταει κωδικο και μετα επιβεβαιωση κωδικου; πως θα το κανεις;
1 Γνώσεις Linux: Ικανοποιητικό ┃ Προγραμματισμού: Ικανοποιητικό ┃ Αγγλικών: Ικανοποιητικό
2 Ubuntu 13.04 raring 3.8.0-30-generic 64bit (en_US.UTF-8, Unity ubuntu), Ubuntu 3.8.0-19-generic, Windows 7
3 Intel Core i7-3537U CPU @ 2.00GHz ‖ RAM 3840 MiB ‖ ASUS K56CB
4 Intel 3rd Gen Core processor Graphics Controller [8086:0166] {i915}
5 wlan0: Atheros Inc. AR9485 Wireless Network Adapter [168c:0032] (rev 01) ⋮ eth0: Realtek RTL8111/8168 PCI Express Gigabit Ethernet controller [10ec:8168] (rev 0a)
clepto
antiwinTUX
antiwinTUX
 
Δημοσιεύσεις: 4102
Εγγραφή: 07 Ιαν 2010, 16:27
Τοποθεσία: Πάτρα
Launchpad: christriant
IRC: Clepto
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό Ilias95 » 02 Ιαν 2012, 01:38

clepto έγραψε:να αλλα οταν σου ζηταει κωδικο και μετα επιβεβαιωση κωδικου; πως θα το κανεις;

δεν μπορώ να καταλάβω. δώσε ένα παράδειγμα του τι θες να κάνεις.
Ilias95
saintTUX
saintTUX
 
Δημοσιεύσεις: 1548
Εγγραφή: 29 Απρ 2011, 23:26
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό clepto » 02 Ιαν 2012, 01:44

τρεξε την εντολη
Κώδικας: Επιλογή όλων
encfs ~/.test ~/test
θα σου πει να δημιουργησει τους φακελους, πατα ναι, και θα σου πει να βαλεις κωδικο, βαζεις και σου λεει να τον ξαναβαλεις για επιβεβαιωση...
κοιτα μετα στο man encfs για την παραμετρο -S, χρησιμοποιω αυτη τη παραμετρο με αυτο
Κώδικας: Επιλογή όλων
p1 = subprocess.Popen([ECHO, passwd], stdout=subprocess.PIPE)
p2 = subprocess.Popen([ENCFS, "-S", enfolderdir, folderdir], stdin=p1.stdout, stdout=subprocess.PIPE)
για να περασω τον κωδικο οταν ειναι να ανοιξω τον φακελο αλλα εκει ζηταει τον κωδικο μια φορα.

οταν ειναι να τον δημιουργησεις στον ζηταει 2, σε αυτη τη περιπτωση τι κανω;
1 Γνώσεις Linux: Ικανοποιητικό ┃ Προγραμματισμού: Ικανοποιητικό ┃ Αγγλικών: Ικανοποιητικό
2 Ubuntu 13.04 raring 3.8.0-30-generic 64bit (en_US.UTF-8, Unity ubuntu), Ubuntu 3.8.0-19-generic, Windows 7
3 Intel Core i7-3537U CPU @ 2.00GHz ‖ RAM 3840 MiB ‖ ASUS K56CB
4 Intel 3rd Gen Core processor Graphics Controller [8086:0166] {i915}
5 wlan0: Atheros Inc. AR9485 Wireless Network Adapter [168c:0032] (rev 01) ⋮ eth0: Realtek RTL8111/8168 PCI Express Gigabit Ethernet controller [10ec:8168] (rev 0a)
clepto
antiwinTUX
antiwinTUX
 
Δημοσιεύσεις: 4102
Εγγραφή: 07 Ιαν 2010, 16:27
Τοποθεσία: Πάτρα
Launchpad: christriant
IRC: Clepto
Εκτύπωση

Re: Τα πάντα για την Python

Δημοσίευσηαπό medigeek » 02 Ιαν 2012, 03:03

Δεν είναι μόνο δύο input που χρειάζεσαι αλλά 5 δυστυχώς (ή 3 αν δημιουργήσεις τους φακέλους):

έγραψε:encfs ~/.testy ~/testy
The directory "/home/savvas/.testy/" does not exist. Should it be created? (y,n) y
The directory "/home/savvas/testy" does not exist. Should it be created? (y,n) y
Creating new encrypted volume.
Please choose from one of the following options:
enter "x" for expert configuration mode,
enter "p" for pre-configured paranoia mode,
anything else, or an empty line will select standard mode.
?> p

Standard configuration selected.

Configuration finished. The filesystem to be created has
the following properties:
Filesystem cipher: "ssl/aes", version 3:0:2
Filename encoding: "nameio/block", version 3:0:1
Key Size: 192 bits
Block Size: 1024 bytes
Each file contains 8 byte header with unique IV data.
Filenames encoded using IV chaining mode.
File holes passed through to ciphertext.

Now you will need to enter a password for your filesystem.
You will need to remember this password, as there is absolutely
no recovery mechanism. However, the password can be changed
later using encfsctl.

New Encfs Password:
Verify Encfs Password:


Βρήκα κάτι:
Κώδικας: Επιλογή όλων

$ read -s -p 'password>' pwd
$ touch ~/.encfs_pwd
$ chmod 600 ~/.encfs_pwd
$ echo "mypassword" >> ~/.encfs_pwd
$ encfs --extpass='/bin/cat ~/.encfs_pwd' ~/.box_enc ~/box


Ίσως να μπορείς να διαβάσεις τον κωδικό από ένα αρχείο με την εντολή /bin/cat:
Κώδικας: Επιλογή όλων
#!/usr/bin/python
class passinput():
def __init__(self):
self.pass1 = ""
self.pass2 = ""
self.askpass()
self.passcheck()

def askpass(self):
self.pass1 = raw_input("Insert your password: ")
self.pass2 = raw_input("Type in your password again: ")

def passcheck(self):
while (self.pass1 != self.pass2):
print("Passwords do not match, try again!")
self.askpass()
print("password is: %s" % (self.pass1))

def startencfs(self):
import os
import os.path
import subprocess
import tempfile
ENCFS = "/usr/bin/encfs"
tmp = tempfile.mkstemp()[1]
with open(tmp, 'w') as f:
f.write(self.pass1)
print("File %s has the password: %s" % (tmp, self.pass1))
extpass = "/bin/cat %s" % (tmp)
enfolderdir = "/home/savvas/.testy"
folderdir = "/home/savvas/testy"
print("Creating folders")
if not os.path.exists(enfolderdir):
os.mkdir(enfolderdir, 0700) # mkdir and chmod 0700
if not os.path.exists(folderdir):
os.mkdir(folderdir, 0700)
print("Running encfs")
p2 = subprocess.Popen([ENCFS, "--extpass", extpass, enfolderdir, folderdir], \
stdout=subprocess.PIPE)


def main():
a = passinput()
a.startencfs()

if __name__ == "__main__":
main()


ή με την εντολή /bin/echo:
Κώδικας: Επιλογή όλων
#!/usr/bin/python
class passinput():
def __init__(self):
self.pass1 = ""
self.pass2 = ""
self.askpass()
self.passcheck()

def askpass(self):
self.pass1 = raw_input("Insert your password: ")
self.pass2 = raw_input("Type in your password again: ")

def passcheck(self):
while (self.pass1 != self.pass2):
print("Passwords do not match, try again!")
self.askpass()
print("password is: %s" % (self.pass1))

def startencfs(self):
import os
import os.path
import subprocess
#import tempfile
ENCFS = "/usr/bin/encfs"
#tmp = tempfile.mkstemp()[1]
#with open(tmp, 'w') as f:
# f.write(self.pass1)
#print("File %s has the password: %s" % (tmp, self.pass1))
extpass = "/bin/echo %s" % (self.pass1)
enfolderdir = "/home/savvas/.testy"
folderdir = "/home/savvas/testy"
print("Creating folders...")
if not os.path.exists(enfolderdir):
os.mkdir(enfolderdir, 0700) # mkdir and chmod 0700
if not os.path.exists(folderdir):
os.mkdir(folderdir, 0700)
print("Running encfs...")
p2 = subprocess.Popen([ENCFS, "--extpass", extpass, enfolderdir, folderdir], \
stdout=subprocess.PIPE)


def main():
a = passinput()
a.startencfs()

if __name__ == "__main__":
main()




έγραψε:$ python test.py
Insert your password: axy783
Type in your password again: axy783
password is: axy783
Creating folders...
Running encfs...

$ encfsctl info ~/.testy/

Version 6 configuration; created by EncFS 1.7.4 (revision 20100713)
Filesystem cipher: "ssl/aes", version 3:0:0 (using 3:0:2)
Filename encoding: "nameio/block", version 3:0:0 (using 3:0:1)
Key Size: 192 bits
Using PBKDF2, with 167419 iterations
Salt Size: 160 bits
Block Size: 1024 bytes
Each file contains 8 byte header with unique IV data.
Filenames encoded using IV chaining mode.
File holes passed through to ciphertext.
Κύπριος; Κόπιασε στο ubuntu-cy! ┃ Launchpad Debian Github
Οδηγός για νεοεισερχόμενους -- Αρχικές οδηγίες για αρχάριους χρήστες του Ubuntu

1 Γνώσεις Linux: Πολύ καλό ┃ Προγραμματισμού: Πολύ καλό ┃ Αγγλικών: Πολύ καλό
2 Ubuntu 12.10 quantal 3.5.0-21-generic 64bit (en_US.UTF-8, GNOME cinnamon2d), Ubuntu 3.5.0-19-generic, Windows 7
3 Intel Core2 Duo CPU E6550 2.33GHz ‖ RAM 5970 MiB ‖ MSI MS-7235
4 nVidia G73 [GeForce 7300 GT] [10de:0393] {nvidia}
5 eth0: Realtek RTL-8110SC/8169SC Gigabit Ethernet [10ec:8167] (rev 10)
Άβαταρ μέλους
medigeek
Freedom
Freedom
 
Δημοσιεύσεις: 5023
Εγγραφή: 24 Μάιος 2008, 14:49
Τοποθεσία: Σερβία/Κύπρος
Launchpad: medigeek
IRC: savvas
Εκτύπωση

ΠροηγούμενηΕπόμενο

Επιστροφή στο Ανάπτυξη Λογισμικού / Αλγόριθμοι