github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

drakulavich / file-splitter

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

python script that split files in folder for cd burning — Read more

  cancel

http://drakulavich.blogspot.com/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

args replace, improve output 
drakulavich (author)
Tue Oct 06 10:24:43 -0700 2009
commit  c17d3b99bc4172d179bb1923159bf701870b61b5
tree    9dc23a199d64c85bf8fe9435f5b9a4ebd6449d80
parent  4c1485cdf108b86885014423e1abfc01fba47325
file-splitter / file-splitter.py file-splitter.py
100755 74 lines (61 sloc) 2.398 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import os, operator, sys
from glob import glob
from optparse import OptionParser
 
usage = "usage: %prog [options] path_to_directory"
parser = OptionParser(usage=usage)
parser.add_option("-s", "--size", type="int", dest="cdsize", default=700,
                  help="block size in megabytes", metavar="MB")
 
(options, args) = parser.parse_args()
 
if len(args) <> 0:
 dir = args[0]
else:
 dir = ""
cdsize = options.cdsize
 
# Проверка заданного каталога
if dir <> "":
 if os.path.isdir(dir):
  if dir[-1] <> "/":
   dir += "/"
 else:
  print "Неверный аргумент!\n",dir,"не является каталогом."
  sys.exit(1)
 
print "Размер блока:",cdsize,"Mb\n"
# Перевод размера в байты
cdsize *= 1024*1024
 
# Создаётся список с именами файлов и их размерами
files = []
for i in glob(dir+"*"):
 if os.path.isfile(i):
  files.append([os.path.basename(i), os.path.getsize(i)])
 
# Проверка длины списка
if len(files) == 0:
 print "Ошибка. Не удалось получить список файлов в каталоге",dir
 sys.exit(1)
 
# Сортировка списка по размеру файла
files.sort(key=operator.itemgetter(1))
# Меняем порядок от большего к меньшему
files.reverse ()
 
# Сравниваем наибольший файл с размером блока
if files[0][1] > cdsize:
 print "Ошибка! Не хватает места."
 sys.exit(1)
 
# В эту переменную записывается количество виртуально записанных дисков
cdnum = 0
 
while len(files)>0:
 # размер добавленных на диск данных
 stsize = 0
 i = 0
 while i<len(files):
  if files[i][1] <= (cdsize - stsize):
   # Если места достаточно, увеличиваем размер добавленных данных
   stsize = stsize + files[i][1]
   print '%.2f'%(files[i][1]/1024/1024.),"\t",files[i][0]
   # Удаляем использованный элемент
   del files[i]
  else:
   i += 1
 cdnum += 1
 # Небольшая статистика
 print "-----\nTotal:\t",'%.2f'%(stsize/1024/1024.),"Mb\nUsage:\t",'%.2f'%(stsize/(cdsize/100.)),"%\n----< ",cdnum," >----\n"
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server