I have some scripts that I'm developing that perform various tasks at the Project level, and I run these as a batch process. I run them at night, when users are (for the most part) not in DOORS. However, on occasion I'll get a message that a Project is locked or that I have an Invalid lock request - data already locked. |
Re: Skip Project if it is "Locked"
Never figures this out adequately. The "string isLocked(item)" command doesn't seem to work on Projects.
bool IsProjectLocked(string NameProj)
{ // Is the project locked?
// Project name has leading slash e.g. "/MyProject", such as
// returned from fullName(Project) <NOT from rootName_(Project)>
Lock lck
string NameLock
for lck in lockList do
{ NameLock = lck.recourceName
if (matches(NameProj, NameLock)) return(true)
}
return(false)
} // end IsProjectLocked()
|
Re: Skip Project if it is "Locked" llandale - Wed Jun 08 14:40:39 EDT 2011
Never figures this out adequately. The "string isLocked(item)" command doesn't seem to work on Projects.
bool IsProjectLocked(string NameProj)
{ // Is the project locked?
// Project name has leading slash e.g. "/MyProject", such as
// returned from fullName(Project) <NOT from rootName_(Project)>
Lock lck
string NameLock
for lck in lockList do
{ NameLock = lck.recourceName
if (matches(NameProj, NameLock)) return(true)
}
return(false)
} // end IsProjectLocked()
so much for scribbling.
bool IsProjectLocked(string NameProj)
{ // Is the project locked?
// Project name has leading slash e.g. "/MyProject", such as
// returned from fullName(Project) <NOT from rootName_(Project)>
Lock lck
string NameLock
LockList llist = getLocksInDatabase(true)
bool Found = false
Item itm
for lck in llist do
{ itm = lck.item
NameLock = fullName(itm)
if (matches(NameProj, NameLock))
{ Found = true
break // stop looking
}
}
delete(llist)
return(Found)
} // end IsProjectLocked()
string NameProj = "/LPD26 Interfaces"
print (IsProjectLocked(NameProj)) "\t" NameProj "\n"
|
Re: Skip Project if it is "Locked" llandale - Wed Jun 08 14:56:34 EDT 2011 so much for scribbling.
bool IsProjectLocked(string NameProj)
{ // Is the project locked?
// Project name has leading slash e.g. "/MyProject", such as
// returned from fullName(Project) <NOT from rootName_(Project)>
Lock lck
string NameLock
LockList llist = getLocksInDatabase(true)
bool Found = false
Item itm
for lck in llist do
{ itm = lck.item
NameLock = fullName(itm)
if (matches(NameProj, NameLock))
{ Found = true
break // stop looking
}
}
delete(llist)
return(Found)
} // end IsProjectLocked()
string NameProj = "/LPD26 Interfaces"
print (IsProjectLocked(NameProj)) "\t" NameProj "\n"
OK. I finally got back to this script and wrote it for archiving projects as part of a batch process. The problem is, if a locked project is found, my script still stops and displays the following in the DOS window:
Lock lockItem
string uname
string proj_name
int pcounter = 0
//Message to user
print "Archiving ...\n"
//Iterate through projects in database
Project p
for p in database do{
//Extract name of current project
string pname = name p
//Get parent project
Project parent = getParentProject(p)
if(null parent && !isDeleted p){
// build the skip list of top level Projects
// pcounter is key, pname is data
Skip projList = create
int projCount = 0
put(projList, pcounter, pname)
// Get Locks
LockList lcklist = getLocksInDatabase(true)
for lockItem in lcklist do {
uname = lockItem.user
proj_name = lockItem.resourceName
}
// for each project in the skip list...
for pname in projList do {
if (proj_name == pname) //if the project name is one that is "locked"
{
continue
print "User: " uname " has Project resource: " proj_name " locked""\n"
}//End if (proj_name == pname)
else //project isn't locked, so archive it
{
string proj_archive = archive (pname,"c:\\DOORS_Projects\\ATS\\"(pname)".dpa",false,true,allBaselines,false)
if (!null proj_archive)
{
ack proj_archive
halt
}// End !null proj_archive
}// End else (proj_name != pname)
pcounter++
projCount++
print pname
print " Done!" "\n"
}// End for pname in projList do
}// End if(null parent && !isDeleted p)
}//End for p in database do
|
Re: Skip Project if it is "Locked" ChrisAnnal - Thu Aug 25 10:18:54 EDT 2011
OK. I finally got back to this script and wrote it for archiving projects as part of a batch process. The problem is, if a locked project is found, my script still stops and displays the following in the DOS window:
Lock lockItem
string uname
string proj_name
int pcounter = 0
//Message to user
print "Archiving ...\n"
//Iterate through projects in database
Project p
for p in database do{
//Extract name of current project
string pname = name p
//Get parent project
Project parent = getParentProject(p)
if(null parent && !isDeleted p){
// build the skip list of top level Projects
// pcounter is key, pname is data
Skip projList = create
int projCount = 0
put(projList, pcounter, pname)
// Get Locks
LockList lcklist = getLocksInDatabase(true)
for lockItem in lcklist do {
uname = lockItem.user
proj_name = lockItem.resourceName
}
// for each project in the skip list...
for pname in projList do {
if (proj_name == pname) //if the project name is one that is "locked"
{
continue
print "User: " uname " has Project resource: " proj_name " locked""\n"
}//End if (proj_name == pname)
else //project isn't locked, so archive it
{
string proj_archive = archive (pname,"c:\\DOORS_Projects\\ATS\\"(pname)".dpa",false,true,allBaselines,false)
if (!null proj_archive)
{
ack proj_archive
halt
}// End !null proj_archive
}// End else (proj_name != pname)
pcounter++
projCount++
print pname
print " Done!" "\n"
}// End for pname in projList do
}// End if(null parent && !isDeleted p)
}//End for p in database do
That's pretty ugly code; if nothing else fix the indentation. A real editor will let you see tabs and spaces which make formatting far easier.
if the current folder isn't at the database level then warn and halt.
create skpProjectsToArchive
for each project in the database
{ if (project has parent project) then advise and continue
if (project is currently locked)then warn and continue
put in skpProjectsToArchive
}
for projects to archive
{ build the project name
archive the project
report archive status
}
delete(skpProjectsToArchive)
|
Re: Skip Project if it is "Locked" llandale - Thu Aug 25 12:07:40 EDT 2011
That's pretty ugly code; if nothing else fix the indentation. A real editor will let you see tabs and spaces which make formatting far easier.
if the current folder isn't at the database level then warn and halt.
create skpProjectsToArchive
for each project in the database
{ if (project has parent project) then advise and continue
if (project is currently locked)then warn and continue
put in skpProjectsToArchive
}
for projects to archive
{ build the project name
archive the project
report archive status
}
delete(skpProjectsToArchive)
|
Re: Skip Project if it is "Locked" David_G_Bond - Thu Aug 25 13:10:19 EDT 2011 But, you could find the locks and delete them and thus making the archive work.
|
Re: Skip Project if it is "Locked" llandale - Thu Aug 25 17:13:56 EDT 2011
If a locked project is encountered during the running of a batch-process DXL script, how can we avoid the locked project. What I want to do is simply continue with the process and skip over the offending (locked) project. I don't want to unlock it for fear of data corruption. I just want to skip it. This would apply to any DXL script that runs on a batch process using {Code} Project p for p in database do { string pname = name p // later in the code example, I put these pnames in a Skip List and do something with each... {Code} I had thought I needed to build a 2nd list of projects that were locked, using "getLocksInDabase" and comparing the results against the "pname"s in the projList Again, all of this was in an effort to simply AVOID those projects that are locked when the batch process is running. I know in other threads of the forum various contributers have suggested kicking users out, unlocking, etc when this type of problem arises, but I was looking for a kinder, gentler approach.. :) |
Re: Skip Project if it is "Locked" ChrisAnnal - Fri Aug 26 09:21:55 EDT 2011 Way up above I wrote the simple "IsProjectLocked" function which you could use in this sort of loop:
for proejct in database
{ if (IsProjectLocked)
then print "Ignoring locked project "
else proceed to archive
}
|
Re: Skip Project if it is "Locked" ChrisAnnal - Fri Aug 26 09:21:55 EDT 2011
My head began hurting, looking at the code so I simplified. If you have proper permissions the following code should work. Just put your code where script says. "//PUT NORMAL PROCESSING HERE"
//FindUnlockedProject
/*Demo to find locked projects*/
Lock lockItem
LockList lcklist
string sProjectName
Project pX
Buffer bx1=create, bx2=create
bool bLockedByAnyUser=true
for pX in database do
{ sProjectName = name pX
lcklist = getLocksInFolder(pX,true,bLockedByAnyUser)
for lockItem in lcklist do {if(matches(sProjectName,bx1 ""))continue;bx1+=sProjectName " locked\n"}
bx2+= sProjectName " is available for processing\n"
//PUT NORMAL PROCESSING HERE
}
print bx1 "\n" bx2""
|
Re: Skip Project if it is "Locked" OurGuest - Mon Aug 29 11:12:46 EDT 2011
My head began hurting, looking at the code so I simplified. If you have proper permissions the following code should work. Just put your code where script says. "//PUT NORMAL PROCESSING HERE"
//FindUnlockedProject
/*Demo to find locked projects*/
Lock lockItem
LockList lcklist
string sProjectName
Project pX
Buffer bx1=create, bx2=create
bool bLockedByAnyUser=true
for pX in database do
{ sProjectName = name pX
lcklist = getLocksInFolder(pX,true,bLockedByAnyUser)
for lockItem in lcklist do {if(matches(sProjectName,bx1 ""))continue;bx1+=sProjectName " locked\n"}
bx2+= sProjectName " is available for processing\n"
//PUT NORMAL PROCESSING HERE
}
print bx1 "\n" bx2""
Your simple solution provided the wrapper that I can use to execute my scripts on projects that are not locked, and avoid those that are locked. This allows scripts not only to run as part of a batch process, but (if needed) they can be run during regular hours and not interfere with users who are currently working in DOORS - since the projects they are working in will be avoided. And thanks to Louie, too. Your advice helped me clean up my existing code. Thanks! Chris Annal SW Test Engineer / DOORS Database Administrator Saab Sensis Corporation, East Syracuse, New York chrisa@saabsensis.com |
Re: Skip Project if it is "Locked" OurGuest - Mon Aug 29 11:12:46 EDT 2011
My head began hurting, looking at the code so I simplified. If you have proper permissions the following code should work. Just put your code where script says. "//PUT NORMAL PROCESSING HERE"
//FindUnlockedProject
/*Demo to find locked projects*/
Lock lockItem
LockList lcklist
string sProjectName
Project pX
Buffer bx1=create, bx2=create
bool bLockedByAnyUser=true
for pX in database do
{ sProjectName = name pX
lcklist = getLocksInFolder(pX,true,bLockedByAnyUser)
for lockItem in lcklist do {if(matches(sProjectName,bx1 ""))continue;bx1+=sProjectName " locked\n"}
bx2+= sProjectName " is available for processing\n"
//PUT NORMAL PROCESSING HERE
}
print bx1 "\n" bx2""
Simpler and faster -- in previous code after I pasted in the code, I deleted "continue" which was needed. But the following will work faster.
//FindUnlockedProject
/*Demo to find locked projects*/
Lock lockItem
LockList lcklist
string sProjectName
Project pX
Buffer bx1=create, bx2=create
bool bLockedByAnyUser=true
for pX in database do
{ sProjectName = name pX
lcklist = getLocksInFolder(pX,true,bLockedByAnyUser)
for lockItem in lcklist do {bx1+=sProjectName " locked\n";break}
bx2+= sProjectName " is available for processing\n"
//PUT NORMAL PROCESSING HERE
}
print bx1 "\n" bx2""
|
Re: Skip Project if it is "Locked" OurGuest - Mon Aug 29 12:53:42 EDT 2011
Simpler and faster -- in previous code after I pasted in the code, I deleted "continue" which was needed. But the following will work faster.
//FindUnlockedProject
/*Demo to find locked projects*/
Lock lockItem
LockList lcklist
string sProjectName
Project pX
Buffer bx1=create, bx2=create
bool bLockedByAnyUser=true
for pX in database do
{ sProjectName = name pX
lcklist = getLocksInFolder(pX,true,bLockedByAnyUser)
for lockItem in lcklist do {bx1+=sProjectName " locked\n";break}
bx2+= sProjectName " is available for processing\n"
//PUT NORMAL PROCESSING HERE
}
print bx1 "\n" bx2""
To keep from processing locked module need boolean bLocked added
//FindUnlockedProject
/*Demo to find locked projects*/
Lock lockItem
LockList lcklist
string sProjectName
Project pX
Buffer bx1=create, bx2=create
bool bLockedByAnyUser=true, bLocked
for pX in database do
{ sProjectName = name pX
lcklist = getLocksInFolder(pX,true,bLockedByAnyUser)
bLocked=false
for lockItem in lcklist do {bLocked=true; bx1+=sProjectName " locked\n";break}
if(bLocked)continue
bx2+= sProjectName " is available for processing\n"
//PUT NORMAL PROCESSING HERE
}
print bx1 "\n" bx2""
|
Re: Skip Project if it is "Locked" OurGuest - Tue Aug 30 07:10:34 EDT 2011
To keep from processing locked module need boolean bLocked added
//FindUnlockedProject
/*Demo to find locked projects*/
Lock lockItem
LockList lcklist
string sProjectName
Project pX
Buffer bx1=create, bx2=create
bool bLockedByAnyUser=true, bLocked
for pX in database do
{ sProjectName = name pX
lcklist = getLocksInFolder(pX,true,bLockedByAnyUser)
bLocked=false
for lockItem in lcklist do {bLocked=true; bx1+=sProjectName " locked\n";break}
if(bLocked)continue
bx2+= sProjectName " is available for processing\n"
//PUT NORMAL PROCESSING HERE
}
print bx1 "\n" bx2""
I see you deleted the "matches" code, which would have failed if Project "ABC" was locked, and then you checked project "AB". This little code doesn't matter but its good form to delete your structures, delete(lcklist) inside the loop and delete the buffers outside.
|
Re: Skip Project if it is "Locked" llandale - Tue Aug 30 14:38:54 EDT 2011
|