V akom je to shelli

Sekcia: Programovanie 19.12.2005 | 20:01
Mato37   Návštevník
Prosim Vas, moze my niekto povedat v akom shelli je tento skript a ako ho spustim? usage: du.py [options] [-d DIR] where directory will be searched for largest subdirectory options: --version show program's version number and e -h, --help show this help message and exit -d DIR directory (default is current) #!/usr/bin/env python import os, sys from optparse import OptionParser def getdirsize(base): size = 0 for root, dirs, files in os.walk(base): for file in files: filepath = os.path.join(root, file) if os.path.islink(filepath): continue size = size + os.path.getsize(filepath) return size usage = "usage: %prog [options] [-d DIR]\n\ where directory will be searched for largest subdirectory" parser = OptionParser(usage, version="%prog version 0.1") parser.add_option("-d", action = "store", type = "string", default = os.getcwd(), dest="dir", help="directory (default is current)") (options, args) = parser.parse_args() if not os.path.isdir(options.dir): print "Sorry, %s is not a valid directory" %options.dir sys.exit(-1) size_max = -1 for directory in os.listdir(options.dir): dir_fullpath = os.path.join(options.dir, directory) if not os.path.isdir(dir_fullpath): continue size = getdirsize(dir_fullpath) if size > size_max: size_max = size dir_max = directory if size_max != -1: print 'Directory "%s" contains largest subdirectory\n\ "%s", with size of %d bytes.'%(options.dir, dir_max, size_max) else: print 'Directory "%s" does not contain any subdirectory' %options.dir
    • Re: V akom je to shelli 19.12.2005 | 16:32
      Avatar Tomáš Srnka Barz čo, už asi všetko  Administrátor
      no myslim, ze to je napisane v Pythone.
      Dlho som robil linuxos.sk, neskôr založil vpsFree.cz, posledných pár rokov ako tech. riaditeľ vo Websupporte
      • Re: Re: V akom je to shelli 19.12.2005 | 16:37
        Mato37   Návštevník
        No dobre ale ako ho spustim? Chcel som tento skript vyskusat, ulozil som si ho pod menom maxvel ale neviem ako ho spustim
        • Re: Re: Re: V akom je to shelli 19.12.2005 | 17:02
          jariq   Návštevník
          Najdi, kde mas v systeme interpret jazyka python.. napriklad cez "whereis python" a potom uved cestu k nemu v prvom riadku na zaciatku skriptu.. Priklad: #!/usr/bin/python Potom to spustis klasicky z aktualneho adresara: ./maxvel (samozrejme treba tomu dat spustitelny atribut)
          • Re: Re: Re: Re: V akom je to shelli 19.12.2005 | 18:00
            zz   Návštevník
            a este treba mat spravne odsadzovanie, inak asi nezbehne
            • Re: Re: Re: Re: Re: V akom je to shelli 19.12.2005 | 20:01
              Avatar nardew debian  Používateľ
              nie asi, ale urcite nezbehne.... odsadzovanie MUSI byt