Commits

kenfred  committed a38135b

Fixing ui messages

  • Participants
  • Parent commits a6239ab

Comments (0)

Files changed (1)

File hgdepends.py

 revFileName     = '.hgdeprev'
 
 
-def note(message):
-    print('\t' + message),
-    #ui.note(message)
+def note(ui, message):
+    #print('\t' + message),
+    ui.note(message)
 
-def warn(message):
-    print('\t' + message),
-    #ui.warn(message)
+def warn(ui, message):
+    #print('\t' + message),
+    ui.warn(message)
 
-def debug(message):
-    print('\t' + message),
-    #ui.debug(message)
+def debug(ui, message):
+    #print('\t' + message),
+    ui.debug(message)
 
 def ClassifyRepo(ui, repo):
     repoClass = 'Regular'
     if os.path.isfile(depFilePath):
         # Determine if the dep repo is the root repo or a module
         if os.path.isfile(revFilePath):
-            note("Module\n")
+            note(ui, "Module\n")
             repoClass = 'Module'
         else:
-            note("Root\n")
+            note(ui, "Root\n")
             repoClass = 'Root'
     elif os.path.isfile(revFilePath):
-        note("Leaf Module\n")
+        note(ui, "Leaf Module\n")
         repoClass = 'LeafModule'
 
     return repoClass
 def GetRepoMapDependencyFilePath(repo):
     return "%s/%s" % (repo.root, mapFileName)
     
-def GetModuleList(rootFilePath):
-    note("Getting dependency group module list\n")
+def GetModuleList(ui, rootFilePath):
+    note(ui, "Getting dependency group module list\n")
     with open(rootFilePath,'r+') as rootFile:
         moduleAliases = []
         moduleSourcePaths = []
 
 def AddDependency(ui, repo, repoClass):
     if repoClass == 'Root' or repoClass == 'Module':
-        note("Adding dependencies for Dependency Group repo at %s\n" % repo.root)
+        note(ui, "Adding dependencies for Dependency Group repo at %s\n" % repo.root)
         
         rootFilePath, modulePath = GetRootFileAndModuleDirectoryPaths(repo, repoClass)
 
 
         # For each dependency
         for depIndex, depChangeset in enumerate(dependencyChangesets):
-            note("Found dependency on %s %s\n" % (dependencySourcePaths[depIndex], depChangeset))
+            note(ui, "Found dependency on %s %s\n" % (dependencySourcePaths[depIndex], depChangeset))
             # Parse the root's '.hgdeproot' file so we can detect
             # redundant dependencies.
             # Note, we need to do this within the depFile loop
             # because this function is recursive, which means the
             # root file could change before the next iteration of
             # this loop occurs.
-            moduleAliases, moduleSourcePaths, moduleChangesets = GetModuleList(rootFilePath)
+            moduleAliases, moduleSourcePaths, moduleChangesets = GetModuleList(ui, rootFilePath)
 
 
             # Try to determine if the requested dependency is 
                 if (depChangeset == moduleChangeset):
                     folderPath = modulePath + '/%s' % moduleAliases[index]
                     repeatModule = True
-                    note("%s %s already exists in dependency group as %s\n" % (dependencySourcePaths[depIndex], depChangeset, moduleAliases[index]))
+                    note(ui, "%s %s already exists in dependency group as %s\n" % (dependencySourcePaths[depIndex], depChangeset, moduleAliases[index]))
                     break
 
             # If this is a new module, bring it into the dependency group.
                     newAliasName = dependencyAliases[depIndex] + '%d' % count
                     count = count + 1
 
-                note("Creating module %s for %s %s\n" % (newAliasName, dependencySourcePaths[depIndex], depChangeset))
+                note(ui, "Creating module %s for %s %s\n" % (newAliasName, dependencySourcePaths[depIndex], depChangeset))
 
                 # Create repo for module
                 folderPath = "%s/%s" % (modulePath, newAliasName)
             try:
                 # Edit the module's reverse dependency file to point back at this repo
                 with open(folderPath + '/' + revFileName, 'a') as revDepFile:
-                    #note("Setting %s as a dependent of module %s\n" % (repo.root, newAliasName))
+                    #note(ui, "Setting %s as a dependent of module %s\n" % (repo.root, newAliasName))
                     revDepFile.write("%s\n" % repo.root)
             except:
-                warn("Couldn't open reverse dependency file\n")
+                warn(ui, "Couldn't open reverse dependency file\n")
                 raise   
 
             mapFilePath = GetRepoMapDependencyFilePath(repo)
             with open(mapFilePath, 'a') as mapFile:
                 # Update the mapFile
-                #note("Mapping %s as a dependency of %s\n" % (newAliasName, repo.root))
+                #note(ui, "Mapping %s as a dependency of %s\n" % (newAliasName, repo.root))
                 mapFile.write("%s = %s\n" % (dependencyAliases[depIndex], folderPath))
 
-def FindAndReplaceChangesetInFile(filePath, sourcePath, changeset, newChangeset):
-    note("Searching %s to find repo from %s and replace %s with %s\n" % (filePath, sourcePath, changeset, newChangeset))    
+def FindAndReplaceChangesetInFile(ui, filePath, sourcePath, changeset, newChangeset):
+    note(ui, "Searching %s to find repo from %s and replace %s with %s\n" % (filePath, sourcePath, changeset, newChangeset))    
     try:
         with open(filePath) as fileObject:
             lines = fileObject.readlines()
             for line in lines:
                 if sourcePath in line and changeset in line:
                     line = line.replace(changeset, newChangeset)
-                    note("Replaced changeset with %s\n" % (newChangeset))
+                    note(ui, "Replaced changeset with %s\n" % (newChangeset))
                 fileObject.write(line)
     except:
-        warn("Couldn't open file\n")
+        warn(ui, "Couldn't open file\n")
         raise
 
-def FindAndRemoveReverseDependency(revFilePath, revDepRepo):
-    note("Searching %s to find and remove %s\n" % (revFilePath, revDepRepo))
+def FindAndRemoveReverseDependency(ui, revFilePath, revDepRepo):
+    note(ui, "Searching %s to find and remove %s\n" % (revFilePath, revDepRepo))
     try:
         with open(revFilePath) as fileObject:
             lines = fileObject.readlines()
                 if revDepRepo not in line:
                     fileObject.write(line)
                 else:
-                    note("%s removed\n" % revDepRepo)
+                    note(ui, "%s removed\n" % revDepRepo)
     except:
-        warn("Couldn't open file\n")
+        warn(ui, "Couldn't open file\n")
         raise
 
 def UpdateDependencyGroupRepo(ui, repo, repoClass):
-    note("Updating Dependency Group Repo at %s\n" % repo.root)
+    note(ui, "Updating Dependency Group Repo at %s\n" % repo.root)
 
     rootFilePath, modulePath = GetRootFileAndModuleDirectoryPaths(repo, repoClass)
 
         # If .hgdeproot doesn't exist, create it
         open(rootFilePath, 'w').close()
 
-    moduleAliases, moduleSourcePaths, moduleChangesets = GetModuleList(rootFilePath)
+    moduleAliases, moduleSourcePaths, moduleChangesets = GetModuleList(ui, rootFilePath)
     
     if repoClass != 'Root':
 
 
         # Update the .hgdep file for all of the repos that depend on this repo.
         for revDepRepoPath in revDepList:
-            FindAndReplaceChangesetInFile(  '%s/%s' % (revDepRepoPath, depFileName), 
+            FindAndReplaceChangesetInFile(  ui,
+                                            '%s/%s' % (revDepRepoPath, depFileName), 
                                             moduleSourcePaths[currentModuleListIndex],
                                             moduleChangesets[currentModuleListIndex],
                                             currentModuleChangeset)
     
         # Update the .hgdeproot file
-        FindAndReplaceChangesetInFile(  rootFilePath, 
+        FindAndReplaceChangesetInFile(  ui,
+                                        rootFilePath, 
                                         moduleSourcePaths[currentModuleListIndex],
                                         moduleChangesets[currentModuleListIndex],
                                         currentModuleChangeset)
     # Search all modules to see which WERE dependents of this repo
     # Remove this repo from their reverse dependcy file
     for alias in moduleAliases:
-        FindAndRemoveReverseDependency("%s/%s/%s" % (modulePath, alias, revFileName), repo.root)
+        FindAndRemoveReverseDependency(ui, "%s/%s/%s" % (modulePath, alias, revFileName), repo.root)
 
     # Delete the map file and let it be recreated.
     mapFilePath = GetRepoMapDependencyFilePath(repo)
         #    if not os.path.isfile(mapFilePath):
         #        open(mapFilePath, 'w').close()
     except:
-        warn("Error in Dependency Group Pre-update Hook\n")
+        warn(ui, "Error in Dependency Group Pre-update Hook\n")
         return
 
 def updatehook(ui, repo, **kwargs):
         if repoClass != 'Regular':
             UpdateDependencyGroupRepo(ui, repo, repoClass)
     except:
-        warn("Error in Dependency Group Update Hook\n")
+        warn(ui, "Error in Dependency Group Update Hook\n")
         return
         
 def changegrouphook(ui, repo, **kwargs):