Ubuntu Türkiye

Yazılım => Uygulama Geliştirme => Konuyu başlatan: Quaoar - 27 Aralık 2013 - 19:51:02

Başlık: Python'da Yaptığım Sistem Bilgi Programı
Gönderen: Quaoar - 27 Aralık 2013 - 19:51:02
Merhaba, yaklaşık 1 sene önce yaptığım(daha doğrusu yapmaya çalıştığım :D) programın kodlarını tekrar bulduğum için sizlerle paylaşmak istedim:
(python2 kodudur)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright Ege Öz
import os
import time
import commands
logosuse="""
  ____
/@    ~-.
\/ __ .- | 
// //  @  alf
"""
logoarch="""
                +               
                #               
               ###               
              #####             
             ######             
            ; #####;           
           +##.#####           
          +##########       
         #############;
        ###############
       #######   #######
     .######;     ;###;`\".
    .#######;     ;#####. 
    #########.   .########`
   ######'           '######
;####                 ####;
##'                     '## 
#'                         `#
"""
logodeb= """
       _,met$$$$$gg.
    ,g$$$$$$$$$$$$$$$P.
  ,g$$P""        ""Y$$.".
,$$P'              `$$$.
',$$P       ,ggs.     `$$b:
`d$$'     ,$P"'   .    $$$
  $$P      d$'     ,    $$P
  $$:      $$.   -    ,d$$'
  $$;      Y$b._   _,d$P'
  Y$$.    `.`"Y$$$$P"'
  `$$b      "-.__
   `Y$$b
     `Y$$.
       `$$b.
         `Y$$b.
           `"Y$b._
            `""''                                   
"""

logounk= """     
              a8888b.   
             d888888b.
             8P"YP"Y88
             8|o||o|88
             8'    .88
             8`._.' Y8.
            d/      `8b.
           dP   .    Y8b.
          d8:'  "  `::88b
         d8"         'Y88b
        :8P    '      :888
         8a.   :     _a88P
       ._/"Yaa_:   .| 88P|
       \    YP"    `| 8P  `.
       /     \.___.d|    .'
       `--..__)8888P`._.' 

"""

achlog = range(34,35)
dbian=range(31,32)
opnsuse=range(32,33)
yazilar=range(1,2)


if os.path.exists('/etc/apt/sources.list'):
    distro= "Debian"

elif os.path.exists("/etc/pacman.conf"):
    distro= "Arch"

elif os.path.exists("/usr/bin/yast"):
    distro= "OpenSuse"

elif os.path.exists("/usr/share/mcc"):
distro="Mageia"

else:
    distro="Unknown"
   
   
def achlg():
    for i in achlog:
        print logoarch.replace("#", "\033[0;%dm#\033[m" % i)

def dfbian():
    for i in dbian:
        print logodeb.replace("$", "\033[0;%dm$\033[m" % i)

def opnsus():
    for i in opnsuse:
        print logosuse.replace("/", "\033[0;%dm/\033[m" % i)
   
       
usrnam=os.getenv ('USER')
desk=os.getenv ("DESKTOP_SESSION")
pcnme=commands.getoutput ("uname -n")
opers=commands.getoutput ("uname -o")
krnlre=commands.getoutput ("uname -r")
archice=commands.getoutput ("uname -m")


if distro=="Debian":
dfbian()

elif distro=="Arch":
achlg()

elif distro=="OpenSuse":
opnsus()

elif distro=="Mageia":
print logounk

elif distro=="Unknown":
print logounk

usrna="User Name: " + usrnam
pcnm="Hostname: " + pcnme
oper="Operating System: " + opers
krnl="Kernel Release: " + krnlre
archi="Architecture: " + archice
dist="Distribution: " + distro
des="Desktop Session: " + desk

sat=time.strftime("%X")

a="Time: " + sat

def bilgi():
for i in yazilar:
print usrna.replace("User Name:", "\033[0;%dmUser Name:\033[m" % i)
print pcnm.replace("Hostname:", "\033[0;%dmHostname:\033[m" % i)
print oper.replace("Operating System:", "\033[0;%dmOperating System:\033[m" % i)
print krnl.replace("Kernel Release:", "\033[0;%dmKernel Release:\033[m" % i)
print archi.replace("Architecture:", "\033[0;%dmArchitecture:\033[m" % i)
print dist.replace("Distribution:", "\033[0;%dmDistribution:\033[m" % i)
print des.replace("Desktop Session:", "\033[0;%dmDesktop Session:\033[m" % i)
print a.replace("Time:", "\033[0;%dmTime:\033[m" % i)

bilgi()
Başlık: Ynt: Python'da Yaptığım Sistem Bilgi Programı
Gönderen: sem - 22 Ocak 2014 - 23:16:33
Elinize sağlık,

Güzel bir kod örneği olmuş. Fakat bilgi alınması paket yöneticilerinden ziyade farklı şekilde elde edilebilir. Bu hali ile Ubuntu için de Debain çıktısı veriyor... =) Tabi anekdot bilgi ve öneri sadece bu =)

cat /etc/*-release

ile ya da 

 lsb_release -a
Başlık: Ynt: Python'da Yaptığım Sistem Bilgi Programı
Gönderen: krwlng - 23 Ocak 2014 - 16:33:38
Bu kodları hatırlar gibiyim, başka bir yerde veya bu forumda bir kez daha paylaşmış mıydınız? Yanlış hatırlamıyorsam Python 2.7 ile çalışıyordu Pthon 3 uyumlu değildi.