license + handle re-adding drive (somewhat)
This commit is contained in:
parent
1011b48877
commit
e2919ae161
14
COPYING
Normal file
14
COPYING
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2010 Sanjay Bhangar <sanjay@camputer.org>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
class File(models.Model):
|
class File(models.Model):
|
||||||
|
fullpath = models.TextField()
|
||||||
|
filename = models.CharField(max_length=512)
|
||||||
|
extension = models.CharField(max_length=10, blank=True)
|
||||||
|
file_size = models.BigIntegerField()
|
||||||
|
date_created = models.DateTimeField()
|
||||||
|
date_modified = models.DateTimeField()
|
||||||
|
date_accessed = models.DateTimeField()
|
||||||
|
sha1sum = models.CharField(max_length=100)
|
||||||
|
mime_type = models.CharField
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
class Video(File):
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,14 @@ def addHardDrive(filename, path):
|
||||||
filePath = join(path, filename)
|
filePath = join(path, filename)
|
||||||
hdName = filename.replace(".txt", "")
|
hdName = filename.replace(".txt", "")
|
||||||
file = open(filePath)
|
file = open(filePath)
|
||||||
if hardDriveExists(hdName):
|
if hd = hardDriveExists(hdName):
|
||||||
return False
|
hd.remove_files()
|
||||||
else:
|
else:
|
||||||
hd = HardDrive(name = hdName)
|
hd = HardDrive(name = hdName)
|
||||||
hd.save()
|
hd.save()
|
||||||
print hdName
|
print hdName
|
||||||
for f in file:
|
for f in file:
|
||||||
addFile(f, hd)
|
addFile(f, hd)
|
||||||
|
|
||||||
def addFile(filePath, hd):
|
def addFile(filePath, hd):
|
||||||
filename = u''
|
filename = u''
|
||||||
|
@ -38,7 +38,11 @@ def addFile(filePath, hd):
|
||||||
print "added " + filename
|
print "added " + filename
|
||||||
|
|
||||||
def hardDriveExists(hdName):
|
def hardDriveExists(hdName):
|
||||||
return False
|
q = HardDrive.objects.filter(name=hdName)
|
||||||
|
if q.count() > 0:
|
||||||
|
return q[0]
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def getFileNameFromPath(filePath):
|
def getFileNameFromPath(filePath):
|
||||||
return os.path.basename(filePath)
|
return os.path.basename(filePath)
|
||||||
|
|
|
@ -2,9 +2,16 @@ from django.db import models
|
||||||
|
|
||||||
class HardDrive(models.Model):
|
class HardDrive(models.Model):
|
||||||
name = models.CharField(max_length = 255, unique = True)
|
name = models.CharField(max_length = 255, unique = True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
# volumeLabel = models.CharField(max_length = 255)
|
|
||||||
|
def remove_files(self):
|
||||||
|
files = File.objects.filter(hd=self)
|
||||||
|
for f in files:
|
||||||
|
f.delete()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class File(models.Model):
|
class File(models.Model):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user