зеркало из https://github.com/mozilla/gecko-dev.git
462 строки
15 KiB
Plaintext
462 строки
15 KiB
Plaintext
(*
|
||
*
|
||
* The contents of this file are subject to the Netscape Public
|
||
* License Version 1.1 (the "License"); you may not use this file
|
||
* except in compliance with the License. You may obtain a copy of
|
||
* the License at http://www.mozilla.org/NPL/
|
||
*
|
||
* Software distributed under the License is distributed on an "AS
|
||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||
* implied. See the License for the specific language governing
|
||
* rights and limitations under the License.
|
||
*
|
||
* The Original Code is mozilla.org code.
|
||
*
|
||
* The Initial Developer of the Original Code is Netscape
|
||
* Communications Corporation. Portions created by Netscape are
|
||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||
* Rights Reserved.
|
||
*
|
||
* Contributor(s):
|
||
*)
|
||
|
||
-- edit.cgi
|
||
--
|
||
-- A very basic CGI example. Use this script as a skeleton for creating more sophisticated
|
||
-- CGIs. All this one does is echo back all the CGI variables passed to it.
|
||
-- As with all AppleScript CGIs, make sure you save this as an application, with the
|
||
-- "Stay Open" and "Never Show Startup Screen" options selected.
|
||
--
|
||
-- This file is part of the WebCenter distribution. You are free to do
|
||
-- whatever you wish with it.
|
||
--
|
||
-- Please report bugs to me, Chris Hawk, chris@slaphappy.com
|
||
|
||
-- Change this to point to the Camelot root directory.
|
||
property gCamelotRoot : "Ringo:Camelot:"
|
||
property gSourceTree : gCamelotRoot & "tree:"
|
||
property gSessionPath : gCamelotRoot & "Raptor.mcvs"
|
||
|
||
-- Create the standard HTTP header. We'll prepend this to any result we return
|
||
property crlf : (ASCII character 13) & (ASCII character 10)
|
||
property http_header : "HTTP/1.0 200 OK" & crlf & "Server: QuidProQuo" & crlf & Â
|
||
"MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf
|
||
|
||
(*
|
||
This is the AppleEvent handler. After this CGI is launched, is spins its wheels waiting for
|
||
an AppleEvent to get here. When it does, this next section of code is executed. After it returns
|
||
its result, it goes back to waiting for another AppleEvent.
|
||
*)
|
||
|
||
on handle CGI request path_args Â
|
||
searching for http_search_args Â
|
||
with posted data post_args Â
|
||
using access method access_method Â
|
||
from address client_address Â
|
||
from user user_name Â
|
||
using password using_password Â
|
||
with user info from_user Â
|
||
from server server_name Â
|
||
via port server_port Â
|
||
executing by script_name Â
|
||
of content type content_type Â
|
||
referred by referrer Â
|
||
from browser user_agent
|
||
|
||
-- This example extracts all the possible variables passed to CGIs.
|
||
-- You probably won't need all of these in a typical CGI,
|
||
-- but it doesn't really hurt to get them.
|
||
|
||
try
|
||
-- Debug the arguments.
|
||
-- return http_header & "<H2>Post Args</H2>" & post_args
|
||
|
||
-- use CGI parser to break apart post_args.
|
||
set formData to (parse CGI arguments post_args)
|
||
|
||
set formAction to (CGI field "formAction" from formData)
|
||
set cvsUser to (CGI field "cvsUser" from formData default value "")
|
||
set cvsPassword to (CGI field "cvsPassword" from formData default value "")
|
||
set projectToEdit to (CGI field "projectToEdit" from formData default value "")
|
||
set filesToAdd to (CGI field "filesToAdd" from formData default value "")
|
||
set filesToRemove to (CGI field "filesToRemove" from formData default value "")
|
||
|
||
-- validate parameters.
|
||
if (cvsUser is "") then
|
||
error "Please specify a valid CVS user name."
|
||
end if
|
||
|
||
if (cvsPassword is "") then
|
||
error "Please specify a valid CVS password."
|
||
end if
|
||
|
||
if (projectToEdit is "") then
|
||
error "Please specify a valid Mac project name."
|
||
end if
|
||
|
||
if (formAction is "Query") then
|
||
return http_header & "<H2>Project Query Results</H2>" & Â
|
||
query_project(cvsUser, cvsPassword, projectToEdit)
|
||
else
|
||
set AppleScript's text item delimiters to {crlf}
|
||
set filesToAddList to tokenize(filesToAdd)
|
||
set filesToRemoveList to tokenize(filesToRemove)
|
||
|
||
return http_header & "<H2>Project Editor Results</H2>" & Â
|
||
edit_project(cvsUser, cvsPassword, projectToEdit, filesToAddList, filesToRemoveList)
|
||
end if
|
||
on error error_message
|
||
-- last ditch attempt, logout of cvs.
|
||
try
|
||
cvs_logout()
|
||
on error
|
||
end try
|
||
-- We're not doing much here, so there shouldn't be any errors, but just in case...
|
||
return http_header & "<H2>Project Editor Error</H2>" & error_message
|
||
end try
|
||
end handle CGI request
|
||
|
||
on query_project(cvsUser, cvsPassword, projectToQuery)
|
||
-- "login" to CVS.
|
||
cvs_login(cvsUser, cvsPassword)
|
||
|
||
-- make sure we have latest versions of all referenced files.
|
||
checkout_files({projectToQuery})
|
||
|
||
-- "logout" of cvs.
|
||
cvs_logout()
|
||
|
||
-- make sure the project is in fact a project file.
|
||
validate_project(projectToQuery)
|
||
|
||
-- used to convert Mac paths to mozilla tree paths.
|
||
set mozillaTreePathOffset to (1 + (count of gSourceTree))
|
||
|
||
set query_results to "<H3>Project: " & projectToQuery & "</H3>"
|
||
|
||
-- perform the query.
|
||
set projectPath to (gSourceTree & replace(projectToQuery, "/", ":"))
|
||
openProject(projectPath)
|
||
set targetsList to getTargets()
|
||
set targetNames to names of targetsList
|
||
repeat with targetNameRef in targetNames
|
||
set targetName to (contents of targetNameRef)
|
||
set query_results to query_results & "<H3>Source files in target " & targetName & ":</H3>"
|
||
setCurrentTarget(targetName)
|
||
set targetFiles to getTargetFiles(targetName)
|
||
repeat with targetFile in targetFiles
|
||
-- only store the path name relative to the source tree itself.
|
||
set targetFilePath to substring(contents of targetFile, mozillaTreePathOffset)
|
||
set query_results to query_results & (replace(targetFilePath, ":", "/") & "<BR>")
|
||
end repeat
|
||
end repeat
|
||
closeProject(projectToQuery)
|
||
|
||
return query_results
|
||
end query_project
|
||
|
||
on edit_project(cvsUser, cvsPassword, projectToEdit, filesToAddList, filesToRemoveList)
|
||
if (filesToAddList = {}) and (filesToRemoveList = {}) then
|
||
return "No files added or removed from project " & projectToEdit & "."
|
||
end if
|
||
|
||
-- "login" to CVS.
|
||
cvs_login(cvsUser, cvsPassword)
|
||
|
||
-- make sure we have latest versions of all referenced files.
|
||
set filesToCheckout to {projectToEdit} & filesToAddList & filesToRemoveList
|
||
checkout_files(filesToCheckout)
|
||
|
||
-- make sure the project is in fact a project file.
|
||
validate_project(projectToEdit)
|
||
|
||
-- perform the edits.
|
||
modify_read_only(projectToEdit)
|
||
if (filesToAddList {}) then add_files(projectToEdit, filesToAddList)
|
||
if (filesToRemoveList {}) then remove_files(projectToEdit, filesToRemoveList)
|
||
|
||
-- finally, check in the project, with a comment stating what was done.
|
||
set checkInComment to summarize_edits(filesToAddList, filesToRemoveList)
|
||
-- if (projectToEdit starts with "mozilla/build/mac/test") then
|
||
checkin_files({projectToEdit}, checkInComment)
|
||
-- end if
|
||
|
||
-- "logout" of cvs.
|
||
cvs_logout()
|
||
|
||
return Â
|
||
"Checked in project: " & projectToEdit & "<BR>" & Â
|
||
"Checkin Comment: " & checkInComment & "<BR>"
|
||
end edit_project
|
||
|
||
(* returns a list of tokens according to AppleScript's text item delimiters. *)
|
||
on tokenize(aString)
|
||
set itemList to {}
|
||
repeat with anItemRef in (text items of aString)
|
||
set anItem to (contents of anItemRef)
|
||
if (anItem "") then
|
||
set itemList to itemList & anItem
|
||
end if
|
||
end repeat
|
||
return itemList
|
||
end tokenize
|
||
|
||
(* replaces oldChar with newChar in a string. *)
|
||
on replace(aString, oldChar, newChar)
|
||
set newString to ""
|
||
repeat with aChar in (every character of aString)
|
||
if (contents of aChar = oldChar) then
|
||
set newString to newString & newChar
|
||
else
|
||
set newString to newString & aChar
|
||
end if
|
||
end repeat
|
||
return newString
|
||
end replace
|
||
|
||
on substring(aString, anOffset)
|
||
set aSubString to ""
|
||
repeat with charIndex from anOffset to (count aString)
|
||
set aSubString to aSubString & (character charIndex of aString)
|
||
end repeat
|
||
return aSubString
|
||
end substring
|
||
|
||
on summarize_edits(aAddedFilesList, aRemovedFilesList)
|
||
set AppleScript's text item delimiters to {", "}
|
||
set addedFiles to (aAddedFilesList as string)
|
||
set removedFiles to (aRemovedFilesList as string)
|
||
set editList to {}
|
||
if (addedFiles "") then
|
||
set editList to editList & ("added files: " & addedFiles)
|
||
end if
|
||
if (removedFiles "") then
|
||
set editList to editList & ("removed files: " & removedFiles)
|
||
end if
|
||
return (editList as string)
|
||
end summarize_edits
|
||
|
||
on cvs_login(aUser, aPassword)
|
||
tell application "MacCVS Pro 2.2.2 debug"
|
||
-- store a reference to the session, for convenience
|
||
set myDoc to the first session
|
||
|
||
-- customize the session for this user.
|
||
tell myDoc
|
||
set the remote user of myDoc to aUser
|
||
set the password of myDoc to aPassword
|
||
end tell
|
||
end tell
|
||
end cvs_login
|
||
|
||
on cvs_logout()
|
||
cvs_login("", "")
|
||
end cvs_logout
|
||
|
||
on checkout_files(aFileList)
|
||
tell application "MacCVS Pro 2.2.2 debug"
|
||
-- store a reference to the session, for convenience
|
||
set myDoc to the first session
|
||
|
||
-- checkout the specified files.
|
||
try
|
||
repeat with aFileRef in aFileList
|
||
set aFile to (contents of aFileRef)
|
||
checkout myDoc module aFile
|
||
end repeat
|
||
on error errMsg number errNum
|
||
-- display dialog "The checkout could not be completed because " & errMsg & return & errNum with icon 0
|
||
error errMsg number errNum
|
||
end try
|
||
end tell
|
||
end checkout_files
|
||
|
||
on checkin_files(aFileList, aCheckinComment)
|
||
tell application "MacCVS Pro 2.2.2 debug"
|
||
-- store a reference to the session, for convenience
|
||
set myDoc to the first session
|
||
|
||
-- display dialog "checking into session " & (name of myDoc)
|
||
|
||
-- checkin the specified files.
|
||
try
|
||
repeat with aFileRef in aFileList
|
||
set aFile to (contents of aFileRef)
|
||
tell myDoc
|
||
-- display dialog "checking in file " & aFile
|
||
check in file aFile comment aCheckinComment
|
||
end tell
|
||
end repeat
|
||
on error errMsg number errNum
|
||
display dialog "The commit could not be completed because " & errMsg & return & errNum with icon 0
|
||
error errMsg number errNum
|
||
end try
|
||
end tell
|
||
end checkin_files
|
||
|
||
(* ensures that only a valid CodeWarrior project is specified for editing. *)
|
||
on validate_project(aProject)
|
||
set projectPath to (gSourceTree & replace(aProject, "/", ":"))
|
||
tell application "Finder"
|
||
set projectFileType to get file type of alias projectPath
|
||
end tell
|
||
if (projectFileType is not "MMPr") then
|
||
error "Can only edit project files. The file: ``" & aProject & "'' isn't a valid CodeWarrior project file."
|
||
end if
|
||
end validate_project
|
||
|
||
(* uses MacCVS to MRO a file. *)
|
||
on modify_read_only(aFilePath)
|
||
tell application "MacCVS Pro 2.2.2 debug"
|
||
-- store a reference to the session, for convenience
|
||
set myDoc to the first session
|
||
tell myDoc
|
||
try
|
||
if (status of file aFilePath is not locally modified) then
|
||
modify read only file aFilePath
|
||
end if
|
||
on error
|
||
-- do nothing; it's ok
|
||
end try
|
||
end tell
|
||
end tell
|
||
end modify_read_only
|
||
|
||
(* CW Pro IDE Interface Handlers. *)
|
||
|
||
on openProject(aProjectFile)
|
||
tell application "CodeWarrior IDE 3.2"
|
||
-- activate
|
||
open aProjectFile
|
||
end tell
|
||
end openProject
|
||
|
||
on closeProject(aProjectFile)
|
||
tell application "CodeWarrior IDE 3.2"
|
||
Close Project
|
||
end tell
|
||
end closeProject
|
||
|
||
on getTargets()
|
||
set targetList to {}
|
||
set nameList to {}
|
||
tell application "CodeWarrior IDE 3.2"
|
||
set currentProject to project document 1
|
||
repeat with targetIndex from 1 to (count of targets of currentProject)
|
||
set currentTarget to (target targetIndex of currentProject)
|
||
set targetList to targetList & {currentTarget}
|
||
set nameList to nameList & {name of currentTarget}
|
||
end repeat
|
||
return {target:targetList, names:nameList}
|
||
end tell
|
||
end getTargets
|
||
|
||
on getTargetFiles(targetKey)
|
||
set targetFiles to {}
|
||
tell application "CodeWarrior IDE 3.2"
|
||
set currentProject to project document 1
|
||
set currentTarget to (target targetKey of currentProject)
|
||
repeat with fileIndex from 1 to (count of target files of currentTarget)
|
||
set targetFile to (target file fileIndex of currentTarget)
|
||
-- only consider text files, since other platforms won't be managing binaries.
|
||
-- also, only consider if target file is directly linked.
|
||
if (type of targetFile is text file) and (linked of targetFile) then
|
||
set targetFiles to targetFiles & {Access Paths of targetFile}
|
||
end if
|
||
end repeat
|
||
end tell
|
||
return targetFiles
|
||
end getTargetFiles
|
||
|
||
on addTargetFile(targetFile, targetList)
|
||
tell application "CodeWarrior IDE 3.2"
|
||
add (project document 1) new target file with data {targetFile} to targets targetList
|
||
end tell
|
||
end addTargetFile
|
||
|
||
on setCurrentTarget(currentTargetName)
|
||
tell application "CodeWarrior IDE 3.2"
|
||
Set Current Target currentTargetName
|
||
end tell
|
||
end setCurrentTarget
|
||
|
||
on removeTargetFile(targetFile)
|
||
tell application "CodeWarrior IDE 3.2"
|
||
Remove Files {targetFile}
|
||
end tell
|
||
end removeTargetFile
|
||
|
||
(* adds a list of "/" delimited file paths to the specified project. *)
|
||
on add_files(aProject, aFileList)
|
||
set projectPath to (gSourceTree & replace(aProject, "/", ":"))
|
||
-- display dialog "adding files to project: " & projectPath
|
||
openProject(projectPath)
|
||
set targetsList to getTargets()
|
||
set targetNames to names of targetsList
|
||
repeat with aFileRef in aFileList
|
||
set aFile to (contents of aFileRef)
|
||
set filePath to (gSourceTree & replace(aFile, "/", ":"))
|
||
-- display dialog "adding file: " & filePath
|
||
try
|
||
addTargetFile(filePath, targetNames)
|
||
on error errMsg number errNum
|
||
try
|
||
-- something failed, try closing/opening project, adding it again.
|
||
closeProject(projectPath)
|
||
openProject(projectPath)
|
||
addTargetFile(filePath, targetNames)
|
||
on error errMsg2 number errNum2
|
||
-- give up, and attempt to at least close the project before bailing.
|
||
try
|
||
closeProject(projectPath)
|
||
on error
|
||
end try
|
||
error "Error adding files: " & errMsg2 number errNum2
|
||
end try
|
||
end try
|
||
end repeat
|
||
closeProject(projectPath)
|
||
end add_files
|
||
|
||
(* removes a list of files from the specified project. *)
|
||
on remove_files(aProject, aFileList)
|
||
set projectPath to (gSourceTree & replace(aProject, "/", ":"))
|
||
-- display dialog "removing files from project: " & projectPath
|
||
openProject(projectPath)
|
||
try
|
||
set targetsList to getTargets()
|
||
set targetNames to names of targetsList
|
||
repeat with targetNameRef in targetNames
|
||
set targetName to (contents of targetNameRef)
|
||
setCurrentTarget(targetName)
|
||
repeat with aFileRef in aFileList
|
||
set aFile to (contents of aFileRef)
|
||
set filePath to (gSourceTree & replace(aFile, "/", ":"))
|
||
-- display dialog "removing file: " & filePath & " from target: " & targetName
|
||
removeTargetFile(filePath)
|
||
end repeat
|
||
end repeat
|
||
on error errMsg number errNum
|
||
try
|
||
closeProject(projectPath)
|
||
on error
|
||
end try
|
||
error "Error removing files: " & errMsg number errNum
|
||
end try
|
||
closeProject(projectPath)
|
||
end remove_files
|
||
|
||
on open_session(aSessionPath)
|
||
tell application "Finder"
|
||
-- open the session file
|
||
open alias aSessionPath
|
||
end tell
|
||
end open_session
|
||
|
||
(* When the CGI is first loaded, this will cause MacCVS to load the Raptor CVS Session file. *)
|
||
|
||
on run
|
||
-- open the MacCVS session file.
|
||
open_session(gSessionPath)
|
||
end run
|