Exemplo n.º 1
0
	def sync (self):
		"""
		workingi over the items selected by "new" and "modified"
		sync new and modified files to repository,
		creating new reference directories when necessary
		"""
		
		
		# print "\nUpdating reference dir"
		self.select (["modified", "new"])
		# print '%d selected for "modified", "new"' % len(self.selected)
		print "%s%s" % (myglobals.getIndent(self.level), self.name)
		for status in self.selected:
			obj = status.fsObj
			# print "status: %s\n\t%s" % (obj.__class__.__name__, obj.path)
			if isinstance (obj, SyncingWorkDirectory):
				# print "DIRECTORY %s" % obj.name
				if not obj.selected.isempty():
					# print "\t NOT empty"
					print "%s%s/" % (myglobals.getIndent(obj.level), obj.name)
					obj.sync ()
			elif  isinstance (obj, SyncWorkingFile):
				print "obj: " + obj.__class__.__name__
				print "%s  (%s)" % (str(obj), status.flag)
				obj.write (self.refdir.path, 1)
			elif isinstance (obj, JloDirectory):
				# this is a reference directory or file, which we don't touch during sync for mow
				pass
			else:
				raise Exception,  "sync encountered unrecognized object %s\n\t%s" % (obj.__class__.__name__, obj.path)
Exemplo n.º 2
0
    def __repr__(self, depth=None):
        """
		use the SELECTED structure to recursively list
		the selected items in this Working Directory
		"""
        s = []
        add = s.append

        add("%s%s" % (myglobals.getIndent(self.level), self.name))
        if depth is None or self.level < depth:
            for status in self.selected:
                obj = status.fsObj
                # if obj.level > depth:
                # # print 'level (%d) exceeds depth, skipping' % obj.level
                # continue
                if isinstance(obj, WorkingDirectory):
                    # print "DIRECTORY %s" % obj.name
                    if not obj.selected.isempty():
                        add(str(obj))
                elif isinstance(obj, JloFile):
                    if os.path.exists(obj.path):
                        add("%s  (%s)!!!" % (str(obj), status.flag))
                        # add ("%s%s  (%s)!!!" % (myglobals.getIndent(self.level), str(obj), status.flag))
                    else:
                        add("%s%s  (%s)???" % (myglobals.getIndent(
                            self.level), str(obj), status.flag))
                else:
                    ## missing directory
                    add("%s%s (missing)##" %
                        (myglobals.getIndent(self.level + 1), obj.name))
        return '\n'.join(s)
Exemplo n.º 3
0
 def listing(self):
     s = []
     add = s.append
     add("%s%s" % (myglobals.getIndent(self.level), self.name))
     for obj in self.dir():
         add(obj.listing())
     return '\n'.join(s)
Exemplo n.º 4
0
 def listing(self):
     # return ("%s %s" % (self.name, self.ppDate (self.modtime)))
     label = self.name
     if self.islink:
         label = "%s (link)" % label
     if self.isalias:
         label = "%s (alias)" % label
     return "%s*%s (%s)" % (myglobals.getIndent(
         self.level), self.name, self.ppDate(self.modtime))
Exemplo n.º 5
0
    def fssync(self, syncdir):
        """
		This approach was abandoned in favor of fscmp because it relied
		to heavily on last mod, which is not a reliable way to judge whether a
		working file should replace a reference file.
		"""
        ## print "%s%s" % (myglobals.getIndent(self.level), self.name)
        for file in self.getfiles():
            # print "sync: %s" % file.name
            refFilePath = os.path.join(syncdir, file.name)
            refFile = None
            try:
                refFile = JloFile(refFilePath)
            except:
                # print "no reference file for " + file.name
                pass
            if not refFile or not file.equals(refFile):
                file.write(syncdir)
                if not file.dowrites:
                    print "%s (NOT WRITTEN)" % file.listing()
                else:
                    print file.listing()
            else:
                REJECTED.append(file)
        for subdir in self.getsubdirs():
            if not subdir.isempty():
                path = os.path.join(syncdir, subdir.name)
                listing = "%s%s/" % (myglobals.getIndent(
                    subdir.level), subdir.name)
                if not os.path.exists(path):
                    listing = "%s*%s/" % (myglobals.getIndent(
                        subdir.level), subdir.name)
                    if JloFilterFile.dowrites:
                        listing = listing + " (created)"
                        # print "\ncreating dir: " + path
                        os.mkdir(path)
                    else:
                        listing = listing + " (new)"
                print listing

                subdir.fssync(path)
Exemplo n.º 6
0
	def __repr__ (self):
		"""
		Generic string representation for File system objects. 
		Indented by "self.level"
		"""
		# return ("%s %s" % (self.name, self.ppDate (self.modtime)))	
		label = self.name
		if self.islink:
			label = "%s (link)" % label
		if self.isalias:
			label = "%s (alias)" % label
		return "%s%s (%s)" % (myglobals.getIndent(self.level), 
							   self.name, 
							   self.ppDate (self.modtime))
Exemplo n.º 7
0
 def listingOld(self):
     s = []
     add = s.append
     add("%s%s" % (myglobals.getIndent(self.level), self.name))
     for obj in self.dir():
         if isinstance(obj, JloDirectory):
             # print "DIRECTORY %s" % obj.name
             if not obj.isempty():
                 # print "\t NOT empty"
                 add(obj.listing())
             else:
                 # print "\t EMPTY"
                 pass
         elif isinstance(obj, JloFilterFile):
             # print "obj: " + obj.__class__.__name__
             add(obj.listing())
         else:
             add("??? %s ???" % obj.name)
     return '\n'.join(s)
Exemplo n.º 8
0
    def listing(self):
        """
		NOTE: this method of defining sort may not work for
		more recent versions of python. 
		check version with sys.version_info
		the sort method below is known to work for v < 2.7.x
		"""
        s = []
        add = s.append
        add("%s%s/" % (myglobals.getIndent(self.level), self.name))
        files = self.getfiles()

        files.sort(lambda x, y: -cmp(x.modtime, y.modtime))
        for file in files:
            add(file.listing())
        for subdir in self.getsubdirs():
            if not subdir.isempty():
                add(subdir.listing())
        return '\n'.join(s)
Exemplo n.º 9
0
	def __repr__ (self):
		s=[];add=s.append
		add ("%s%s/" % (myglobals.getIndent(self.level), self.name))
		for obj in self.dir():
			add (str(obj))
		return '\n'.join (s)
Exemplo n.º 10
0
 def listing(self):
     # return ("%s %s" % (self.name, self.ppDate (self.modtime)))
     return "%s%s (%s)" % (myglobals.getIndent(
         self.level), self.name, self.ppDate(self.modtime))