User:Mlehari: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Mlehari (talk | contribs)
No edit summary
Mlehari (talk | contribs)
No edit summary
 
Line 1: Line 1:
== QUEST 7 ==
<source lang="bash">
<source lang="bash">
#!/bin/bash
#!/bin/bash
Line 61: Line 62:
echo "Great success!"
echo "Great success!"
echo "Kasutaja $KASUTAJA lisati gruppi $GRUPP"
echo "Kasutaja $KASUTAJA lisati gruppi $GRUPP"
</source>
== QUEST 41 ==
<source lang="python">
#!/usr/bin/python
# -*- coding: utf-8 -*-
####################################################################
#                                                                  #
# Skript, mis loeb standardsisendist teksti ja tõlgib selle leeti. #
# Tulemus kirjutatakse standardväljundisse.                        #
#                                                                  #
# Versioon 1.0    5. juuni 2011                                    #
# Autor: Martin Lehari                                            #
#                                                                  #
####################################################################
import sys
def asenda(s, sisse, v2lja):
    for a, b in zip(sisse, v2lja):
        s = s.replace(a, b)
    return s
# tõlgitavad sõnad
s6nad_sisse = ["you","are","the"]
s6nad_v2lja = ["u"  ,"r"  ,"teh"]
# asendatavad tähed
t2hed_sisse = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
t2hed_v2lja = ["4","b","©","d","3","f","g","H","!","j","K","l","m","ñ","0","p","q","r","$","t","u","v","w","x","¥","z","@","b","©","d","3","f","g","H","!","j","K","l","m","ñ","0","p","q","R","$","t","u","v","w","x","¥","z"]
print "Tahad olla 1337 haxx0r aga lingvistilistest oskustest jääb vajaka?"
print "Appi tõttab spetsiaalne tõlkerakendus."
print "Sisesta tõlkimist vajav fraas/lause ja pressi Enter."
print "Töö lõpetamiseks vajuta lihtsalt Enter. \n"
while 1:
    lause = raw_input("Tõlgi seda: ")
   
    if lause == "":
        print "k thx bye!"
        sys.exit(0)
    leet = asenda(lause, s6nad_sisse, s6nad_v2lja)   
    leet = asenda(leet, t2hed_sisse, t2hed_v2lja)
    print "-> " + leet + "\n"
</source>
</source>

Latest revision as of 15:16, 5 June 2011

QUEST 7

#!/bin/bash
#Autor: Martin Lehari
#Versioon: 1.0

# kontrollida parameetreid ja teavitada kasutajat
if [ $# -eq 2 ]; then
	KASUTAJA=$1
	GRUPP=$2
else
	echo "Kasuta seda skripti järgnevalt:"
	echo "$(basename $0) <KASUTAJA> <GRUPP>"
	exit 1
fi

# kontrollime skripti käivitanud kasutaja õiguseid 
if [ $UID -ne 0 ]; then
	echo "V I G A !"
	echo "Skripti $(basename $0) tuleb kasutada juurkasutaja õigustes!"
	exit 1
fi

# Tervitustekst
echo "Luuakse kasutaja $KASUTAJA ja lisatakse gruppi $GRUPP"
echo "Kui sellist gruppi ei eksisteeri, siis see luuakse"

# kontrollime kasutaja olemasolu
if [ $(getent passwd $KASUTAJA) ]; then
    echo "* Kasutaja $KASUTAJA on juba olemas."
else
    echo "* Kasutajat $KASUTAJA ei leitud. Kas loon? (Y/N)"
    read -s -n 1 SISEND
    if [ $SISEND == "y" ]; then
        useradd $KASUTAJA
    else
        echo "Katkestan töö!"
        exit 1
    fi    
fi

# kontrollime grupi olemasolu
if [ $(getent group $GRUPP) ]; then
    echo "* Grupp $GRUPP on olemas."
else
    echo "* Gruppi $GRUPP ei leitud. Kas loon? (Y/N)"   
    read -s -n 1 SISEND
    if [ $SISEND == "y" ]; then
        addgroup $GRUPP &> /dev/null
    else
        echo "Katkestan töö!"
        exit 1
    fi
fi

# lisame kasutaja gruppi
# ideeliselt võiks kasutada ka "useradd -G <GRUPP> <KASUTAJA>" käsku
echo "* Lisan kasutaja gruppi $GRUPP"
usermod -g $GRUPP $KASUTAJA &> /dev/null -G -a

# teatame, et kõik on OK
echo "Great success!"
echo "Kasutaja $KASUTAJA lisati gruppi $GRUPP"


QUEST 41

#!/usr/bin/python
# -*- coding: utf-8 -*-

####################################################################
#                                                                  #
# Skript, mis loeb standardsisendist teksti ja tõlgib selle leeti. #
# Tulemus kirjutatakse standardväljundisse.                        #
#                                                                  #
# Versioon 1.0    5. juuni 2011                                    #
# Autor: Martin Lehari                                             #
#                                                                  #
####################################################################

import sys

def asenda(s, sisse, v2lja):
    for a, b in zip(sisse, v2lja):
        s = s.replace(a, b)
    return s

# tõlgitavad sõnad
s6nad_sisse = ["you","are","the"]
s6nad_v2lja = ["u"  ,"r"  ,"teh"]

# asendatavad tähed
t2hed_sisse = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
t2hed_v2lja = ["4","b","©","d","3","f","g","H","!","j","K","l","m","ñ","0","p","q","r","$","t","u","v","w","x","¥","z","@","b","©","d","3","f","g","H","!","j","K","l","m","ñ","0","p","q","R","$","t","u","v","w","x","¥","z"]


print "Tahad olla 1337 haxx0r aga lingvistilistest oskustest jääb vajaka?"
print "Appi tõttab spetsiaalne tõlkerakendus."
print "Sisesta tõlkimist vajav fraas/lause ja pressi Enter."
print "Töö lõpetamiseks vajuta lihtsalt Enter. \n"

while 1:
    lause = raw_input("Tõlgi seda: ")
    
    if lause == "":
        print "k thx bye!"
        sys.exit(0)

    leet = asenda(lause, s6nad_sisse, s6nad_v2lja)    
    leet = asenda(leet, t2hed_sisse, t2hed_v2lja)
    print "-> " + leet + "\n"