Permalink
Browse files

Finished move and copy

  • Loading branch information...
pksunkara committed Sep 17, 2011
1 parent f6cc19e commit 8960565ba48d09daba046d94db4fb088c2c37c40
Showing with 57 additions and 2 deletions.
  1. +1 −1 __main__.py
  2. +24 −0 dBins/cp.py
  3. +25 −0 dBins/mv.py
  4. +4 −1 dFile.py
  5. +3 −0 dFolder.py
View
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import sys, logging
+import sys, logging, copy
from dFile import dFile
from dFolder import dFolder
from dDrive import dDrive
View
@@ -0,0 +1,24 @@
+argsLen = len(args)
+
+if argsLen==3:
+ args[1] = args[1][:-1] if args[1][-1]=='/' else args[1]
+ tmpS = folder.traverse(list(reversed(args[1].split('/'))), drive)
+ args[2] = args[2][:-1] if args[2][-1]=='/' else args[2]
+ tmpD = folder.traverse(list(reversed(args[2].split('/')[:-1])), drive)
+ tmpDN = args[2].split('/')[-1]
+
+ if tmpS is None:
+ nfd(args[1])
+ else:
+ buf = copy.deepcopy(tmpS)
+ if tmpD is None or isinstance(tmpD, dFile):
+ nfd(args[2])
+ else:
+ new = tmpD.find(tmpDN)
+ if isinstance(new, dFolder): tmpD = new
+ if not isinstance(new, dFolder) and tmpDN not in ['.','..']: buf.name = tmpDN
+ buf.parent = tmpD
+ if isinstance(new, dFile): new.remove()
+ tmpD.add(buf)
+else:
+ cnu(args[0])
View
@@ -0,0 +1,25 @@
+argsLen = len(args)
+
+if argsLen==3:
+ args[1] = args[1][:-1] if args[1][-1]=='/' else args[1]
+ tmpS = folder.traverse(list(reversed(args[1].split('/'))), drive)
+ args[2] = args[2][:-1] if args[2][-1]=='/' else args[2]
+ tmpD = folder.traverse(list(reversed(args[2].split('/')[:-1])), drive)
+ tmpDN = args[2].split('/')[-1]
+
+ if tmpS is None:
+ nfd(args[1])
+ else:
+ buf = copy.deepcopy(tmpS)
+ if tmpD is None or isinstance(tmpD, dFile):
+ nfd(args[2])
+ else:
+ new = tmpD.find(tmpDN)
+ if isinstance(new, dFolder): tmpD = new
+ if not isinstance(new, dFolder) and tmpDN not in ['.','..']: buf.name = tmpDN
+ buf.parent = tmpD
+ if isinstance(new, dFile): new.remove()
+ tmpD.add(buf)
+ tmpS.remove()
+else:
+ cnu(args[0])
View
@@ -12,11 +12,14 @@ def __init__(self, name, data, parent):
def read(self):
return self.data
+ def getSize(self):
+ return str(self.size)+'B' if self.size<1024 else str(round(self.size/1024.0,1))+'KB'
+
def printf(self):
print self.name+" ",
def printl(self):
- print "-%s%s%s\t%sB\t%s"%('rw-', 'rw-', 'r--', self.size, self.name)
+ print "-%s%s%s\t%s\t%s"%('rw-', 'rw-', 'r--', self.getSize(), self.name)
def remove(self):
self.parent.files.remove(self)
View
@@ -11,6 +11,9 @@ def __init__(self, name, parent):
self.perms = 755
self.parent = parent
+ def add(self, f):
+ self.addFile(f) if isinstance(f,dFile) else self.addFolder(f)
+
def addFile(self, f):
self.files.append(f)

0 comments on commit 8960565

Please sign in to comment.