Skip to content
Extraits de code Groupes Projets
Valider d7802724 rédigé par Thomas Saquet's avatar Thomas Saquet
Parcourir les fichiers

added Amons function from MR 35

parent 8a59c41e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
// Untested! // Untested!
// This file has only been merged into master because it depended on the Repo Unification Process // This file has only been merged into master because it depended on the Repo Unification Process
// Which caused a lot of merge conflicts, so reducing merge requests made life easier for everybody at the time // Which caused a lot of merge conflicts, so reducing merge requests made life easier for everybody at the time
...@@ -55,4 +55,15 @@ imports.antilog.rollback = function() ...@@ -55,4 +55,15 @@ imports.antilog.rollback = function()
cache = imports.antilog.cache cache = imports.antilog.cache
if not cache then return if not cache then return
cache.copy("/var/","system.log") cache.copy("/var/","system.log")
end function end function
\ No newline at end of file
imports.antilog.silentClean = function ()
log = imports.antilog.check()
if not log then return
HOST.touch("/var","system.bak")
syslog.delete
syslogbak = HOST.File("/var/system.bak")
syslogbak.set_content("No IPs Today :D")
syslogbak.move("/var", "system.log")
end function
...@@ -76,13 +76,13 @@ imports.file.save = function(content, path, name, origin=null) ...@@ -76,13 +76,13 @@ imports.file.save = function(content, path, name, origin=null)
if data.len > 1 then if data.len > 1 then
for i in range(0, data.len-2) for i in range(0, data.len-2)
name = data[i] name = data[i]
if name == "" then continue if name == "" then continue
comp.create_folder(path, name) comp.create_folder(path, name)
path = path +"/"+ name path = path +"/"+ name
end for end for
end if end if
name = data[data.len-1] name = data[data.len-1]
path = imports.file.PatchPath(path, origin) path = imports.file.PatchPath(path, origin)
file = comp.File(path+name) file = comp.File(path+name)
if not file then if not file then
...@@ -109,21 +109,21 @@ imports.file.PatchPath = function(path, origin=null) ...@@ -109,21 +109,21 @@ imports.file.PatchPath = function(path, origin=null)
if path == null then path = "" if path == null then path = ""
if path.len == 0 or path[-1:] != "/" then path = path + "/" if path.len == 0 or path[-1:] != "/" then path = path + "/"
if origin == null then return path if origin == null then return path
path = path[1:] path = path[1:]
isUser = imports.utils.starts_with(path, "home/") isUser = imports.utils.starts_with(path, "home/")
isRoot = imports.utils.starts_with(path, "root/") isRoot = imports.utils.starts_with(path, "root/")
// Strips the user-part of the path : /root/XXX => /home/XXX ; /home/USER/XXX => /home/XXX ; /home/XXX => /home/XXX // Strips the user-part of the path : /root/XXX => /home/XXX ; /home/USER/XXX => /home/XXX ; /home/XXX => /home/XXX
if isUser or isRoot then if isUser or isRoot then
path = path[path.indexOf("/")+1:] // Removes /root/ or /home/ path = path[path.indexOf("/")+1:] // Removes /root/ or /home/
// Special case: skipping if home without a user // Special case: skipping if home without a user
if isUser and imports.utils.char_count(path, "/") != 1 then path = path[path.indexOf("/")+1:] // Removes the username if isUser and imports.utils.char_count(path, "/") != 1 then path = path[path.indexOf("/")+1:] // Removes the username
path = "home/"+path path = "home/"+path
end if end if
return "/server/remote/"+path return "/server/remote/"+path
end function end function
...@@ -175,10 +175,10 @@ imports.file.FileAccess = function(file, perms, shout=true) ...@@ -175,10 +175,10 @@ imports.file.FileAccess = function(file, perms, shout=true)
if not file then return false if not file then return false
for i in range(0,perms.len-1) for i in range(0,perms.len-1)
perm = perms[i] perm = perms[i]
// Ugly hack: directories don't need r or x permission to enumerate files // Ugly hack: directories don't need r or x permission to enumerate files
if file.is_folder and perm != "w" then continue if file.is_folder and perm != "w" then continue
if file.has_permission(perm) then continue if file.has_permission(perm) then continue
if shout then imports.utils.Print("Error: can't use ('"+perm+"') contents of '"+file.path+"'") if shout then imports.utils.Print("Error: can't use ('"+perm+"') contents of '"+file.path+"'")
return false return false
...@@ -198,10 +198,10 @@ imports.file.GetDir = function(path) ...@@ -198,10 +198,10 @@ imports.file.GetDir = function(path)
return path[0:path.lastIndexOf("/")] return path[0:path.lastIndexOf("/")]
end function end function
// Like GetDir but return a file instead of a path // Like GetDir but return a file instead of a path
// Unlike GetDir, the result doesn't change if the file is already a folder! // Unlike GetDir, the result doesn't change if the file is already a folder!
imports.file.GetDirRef = function(folder) imports.file.GetDirRef = function(folder)
if folder.is_folder then return folder if folder.is_folder then return folder
return folder.parent return folder.parent
end function end function
// Determines the filename from a String path // Determines the filename from a String path
imports.file.GetName = function(path) imports.file.GetName = function(path)
...@@ -233,6 +233,17 @@ imports.file.ReadAllLines = function(file, origin=null) ...@@ -233,6 +233,17 @@ imports.file.ReadAllLines = function(file, origin=null)
return content.split(imports.file.NEW_LINE) return content.split(imports.file.NEW_LINE)
end function end function
imports.file.checkDuplicates = function(file)
lines = file.content.split(char(10))
lines_no_duplicates = []
for line in lines
if line == "" or line == " " then continue
if lines_no_duplicates.indexOf(line) == null then lines_no_duplicates.push(line)
end for
file.set_content(lines_no_duplicates.join(char(10)))
end function
// Creates an object X of version Y in a dir PATH/X/X.Y.ext // Creates an object X of version Y in a dir PATH/X/X.Y.ext
imports.file.VersionedFilePath = function(path, filename) imports.file.VersionedFilePath = function(path, filename)
parts = filename.split(".") parts = filename.split(".")
...@@ -270,7 +281,7 @@ imports.file._DottedString = function(arr) ...@@ -270,7 +281,7 @@ imports.file._DottedString = function(arr)
return result return result
end function end function
// Get the file name from a path and remove double extensions // Get the file name from a path and remove double extensions
// "Scripts/preprocessor.gs.src" => "preprocessor" // "Scripts/preprocessor.gs.src" => "preprocessor"
imports.file.FileNameNoExt = function(path) imports.file.FileNameNoExt = function(path)
index = path.lastIndexOf("/") index = path.lastIndexOf("/")
...@@ -282,7 +293,7 @@ end function ...@@ -282,7 +293,7 @@ end function
// Generates a String with random characters // Generates a String with random characters
// Perfect for a temp file! // Perfect for a temp file!
imports.file.random = function(len) imports.file.random = function(len)
chars = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] chars = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
result = "" result = ""
for i in range(1,len) for i in range(1,len)
......
...@@ -14,14 +14,14 @@ ui = imports.ui ...@@ -14,14 +14,14 @@ ui = imports.ui
imports.ui.FormatMatrix = function(matrix, padding=null) imports.ui.FormatMatrix = function(matrix, padding=null)
if padding == null then padding = imports.ui.PADDING if padding == null then padding = imports.ui.PADDING
text = "" text = ""
nextLine = false nextLine = false
for line in matrix for line in matrix
if nextLine then text = text + imports.file.NEW_LINE else nextLine = true if nextLine then text = text + imports.file.NEW_LINE else nextLine = true
nextCell = false nextCell = false
text = text + imports.utils.PrintList(line, padding) text = text + imports.utils.PrintList(line, padding)
end for end for
return text return text
end function end function
...@@ -31,14 +31,14 @@ imports.ui.PADDING = imports.ui.SPACE+imports.ui.SPACE ...@@ -31,14 +31,14 @@ imports.ui.PADDING = imports.ui.SPACE+imports.ui.SPACE
// Changes a character // Changes a character
imports.ui.ReplacePos = function(text, pos, char) imports.ui.ReplacePos = function(text, pos, char)
return imports.utils.leftSlice(cell,pos) + char + imports.utils.rightSlice(cell,pos+1) return imports.utils.leftSlice(cell,pos) + char + imports.utils.rightSlice(cell,pos+1)
end function end function
// Changes a two-dimensional array into the DATA from format_column // Changes a two-dimensional array into the DATA from format_column
// Spaces are treated as normal text data, space padding is only inserted between the cells of the matrix // Spaces are treated as normal text data, space padding is only inserted between the cells of the matrix
imports.ui.FormattedCols = function(matrix) imports.ui.FormattedCols = function(matrix)
indexes = [] indexes = []
for line in matrix for line in matrix
indexData = [];indexes.push(indexData) indexData = [];indexes.push(indexData)
for i in range(0,line.len-1) for i in range(0,line.len-1)
...@@ -58,7 +58,7 @@ imports.ui.FormattedCols = function(matrix) ...@@ -58,7 +58,7 @@ imports.ui.FormattedCols = function(matrix)
data = format_columns(imports.ui.FormatMatrix(matrix, " ")).split(imports.file.NEW_LINE) data = format_columns(imports.ui.FormatMatrix(matrix, " ")).split(imports.file.NEW_LINE)
matrix = [] matrix = []
for line in data for line in data
cells = [];matrix.push(cells) cells = [];matrix.push(cells)
lastCut = 0 lastCut = 0
...@@ -90,7 +90,7 @@ imports.ui.FormattedCols = function(matrix) ...@@ -90,7 +90,7 @@ imports.ui.FormattedCols = function(matrix)
line[i] = cell line[i] = cell
end for end for
end for end for
return matrix return matrix
end function end function
...@@ -115,3 +115,7 @@ imports.ui.BOLD_END = "</b>" ...@@ -115,3 +115,7 @@ imports.ui.BOLD_END = "</b>"
imports.ui.Bold = function(text) imports.ui.Bold = function(text)
return imports.ui.BOLD+text+imports.ui.BOLD_END return imports.ui.BOLD+text+imports.ui.BOLD_END
end function end function
import.ui.centerText = function(string)
print(" "*(100 - (string.len/2))+string)
end function
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter