From e2919ae16181c5af86fae25c13fc2decc5017cbb Mon Sep 17 00:00:00 2001 From: sanj Date: Thu, 25 Nov 2010 11:18:39 +0100 Subject: [PATCH] license + handle re-adding drive (somewhat) --- COPYING | 14 ++++++++++++++ index/files/models.py | 13 ++++++++++++- index/harddrives/importFromTxtFiles.py | 14 +++++++++----- index/harddrives/models.py | 9 ++++++++- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 COPYING diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..c97633a --- /dev/null +++ b/COPYING @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2010 Sanjay Bhangar + + 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. + diff --git a/index/files/models.py b/index/files/models.py index 6eb5902..d6b2644 100644 --- a/index/files/models.py +++ b/index/files/models.py @@ -1,8 +1,19 @@ from django.db import models 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: abstract = True # Create your models here. + +class Video(File): + diff --git a/index/harddrives/importFromTxtFiles.py b/index/harddrives/importFromTxtFiles.py index b70b30c..b09e91b 100644 --- a/index/harddrives/importFromTxtFiles.py +++ b/index/harddrives/importFromTxtFiles.py @@ -16,14 +16,14 @@ def addHardDrive(filename, path): filePath = join(path, filename) hdName = filename.replace(".txt", "") file = open(filePath) - if hardDriveExists(hdName): - return False + if hd = hardDriveExists(hdName): + hd.remove_files() else: hd = HardDrive(name = hdName) hd.save() print hdName - for f in file: - addFile(f, hd) + for f in file: + addFile(f, hd) def addFile(filePath, hd): filename = u'' @@ -38,7 +38,11 @@ def addFile(filePath, hd): print "added " + filename def hardDriveExists(hdName): - return False + q = HardDrive.objects.filter(name=hdName) + if q.count() > 0: + return q[0] + else: + return False def getFileNameFromPath(filePath): return os.path.basename(filePath) diff --git a/index/harddrives/models.py b/index/harddrives/models.py index 5c66dff..a206fee 100644 --- a/index/harddrives/models.py +++ b/index/harddrives/models.py @@ -2,9 +2,16 @@ from django.db import models class HardDrive(models.Model): name = models.CharField(max_length = 255, unique = True) + def __unicode__(self): 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):