[Mono-list] Update class status?

Gaurav Vaish Gaurav.Vaish@iitk.ac.in
Fri, 12 Apr 2002 00:41:39 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_003E_01C1E1BA.CED66BD0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_003F_01C1E1BA.CED66BD0"


------=_NextPart_001_003F_01C1E1BA.CED66BD0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Update class status?HI,
    I made a small tool to do so for myself.
    If you need it, I am attaching it with this mail. But the input is =
assumed to be in a specific format. Once you read the initial comments =
in any of my commits (*.cs files), you can easily make out.

HIH

Cheers,
Gaurav Vaish
http://home.iitk.ac.in/student/gvaish
http://calendar.yahoo.com/mastergaurav
---------------------------------


  ----- Original Message -----=20
  From: Patrik Torstensson=20
  To: mono-list@ximian.com=20
  Sent: Thursday, April 11, 2002 23:15
  Subject: [Mono-list] Update class status?


  Hi all,=20

  Can I generate a new class status page by my self?=20

  - Patrik=20


------=_NextPart_001_003F_01C1E1BA.CED66BD0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Update class status?</TITLE>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3018.900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>HI,</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; I made a small tool to do so for=20
myself.</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; If you need it, I am attaching it =
with this=20
mail. But the input is assumed to be in a specific format. Once you read =
the=20
initial comments in any of my commits (*.cs files), you can easily make=20
out.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>HIH</FONT></DIV>
<DIV><BR>Cheers,<BR>Gaurav Vaish<BR><A=20
href=3D"http://home.iitk.ac.in/student/gvaish">http://home.iitk.ac.in/stu=
dent/gvaish</A><BR><A=20
href=3D"http://calendar.yahoo.com/mastergaurav">http://calendar.yahoo.com=
/mastergaurav</A><BR>---------------------------------</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:totte@labs2.com" title=3Dtotte@labs2.com>Patrik =
Torstensson</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:mono-list@ximian.com"=20
  title=3Dmono-list@ximian.com>mono-list@ximian.com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Thursday, April 11, 2002=20
23:15</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Mono-list] Update =
class=20
  status?</DIV>
  <DIV><BR></DIV><!-- Converted from text/rtf format -->
  <P><FONT face=3DVerdana size=3D2>Hi all,</FONT> </P>
  <P><FONT face=3DVerdana size=3D2>Can I generate a new class status =
page by my=20
  self? </FONT></P>
  <P><FONT face=3DVerdana size=3D2>- Patrik</FONT> =
</P></BLOCKQUOTE></BODY></HTML>

------=_NextPart_001_003F_01C1E1BA.CED66BD0--

------=_NextPart_000_003E_01C1E1BA.CED66BD0
Content-Type: application/octet-stream;
	name="ClassElement.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ClassElement.cs"

/*
 * Namespace: com.mastergaurav.utils
 * Class:     ClassElement
 *=20
 * Maintainer: mastergaurav@users.sourceforge.net
 * Name:       Gaurav Vaish
 * Status:     100%
 * Implementation: yes
 * Test-Suite: yes
 *=20
 * (C) Gaurav Vaish, 2001
 */

using System.IO;
using System;
using System.Collections;

namespace CSDOC.Utils
{
	public class ClassElement
	{
		private string className;
		private string lastActivity;
		private string implementation;
		private string testSuite;
		private string completion;
		private ArrayList maintainers;

		public const string LAST_ACT =3D "last-activity";
		public const string IMPL     =3D "implementation";
		public const string TS       =3D "test-suite";
		public const string COMPL    =3D "completion";
		public const string MAINTS   =3D "maintainers";
		public const string MAINT    =3D "maintainer";

		public bool IsAllSet()
		{
			return (className!=3Dnull && maintainers!=3Dnull && =
maintainers.Count>0);
		}
	=09
		public string GetXmlData(string tab)
		{
			if(className!=3Dnull)
			{
				string retVal =3D tab + "\t<class name=3D\"";
				retVal +=3D className;
				retVal +=3D "\">\n";
				retVal +=3D (tab + "\t\t<" + LAST_ACT + ">" + lastActivity + "</" + =
LAST_ACT + ">\n");
				retVal +=3D (tab + "\t\t<" + IMPL + ">" + implementation + "</" + =
IMPL + ">\n");
				retVal +=3D (tab + "\t\t<" + TS + ">" + testSuite + "</" + TS + =
">\n");
				retVal +=3D (tab + "\t\t<" + COMPL + ">" + completion + "</" + COMPL =
+ ">\n");
				retVal +=3D (tab + "\t\t<" + MAINTS + ">\n");
				for(int i=3D0; i < maintainers.Count; i++)
				{
					retVal +=3D (tab + "\t\t\t<" + MAINT + ">");
					retVal +=3D ((string)maintainers[i]);
					retVal +=3D ("</" + MAINT + ">\n");
				}
				retVal +=3D (tab + "\t\t</" + MAINTS + ">\n");
				retVal +=3D (tab + "\t</class>\n");
				return retVal;
			}
			return null;
		}

		public ClassElement(string className)
		{
			this.className =3D className;
			Initialize();
		}
	=09
		protected void Initialize()
		{
			lastActivity =3D String.Empty;
			implementation =3D "yes";
			testSuite =3D "no";
			completion =3D "0%";
			maintainers =3D new ArrayList();
		}
	=09
		public string LastActivity
		{
			get
			{
				return lastActivity;
			}
			set
			{
				lastActivity =3D value;
			}
		}
	=09
		public string Implementation
		{
			get
			{
				return implementation;
			}
			set
			{
				implementation =3D value;
			}
		}
	=09
		public string TestSuite
		{
			get
			{
				return testSuite;
			}
			set
			{
				testSuite =3D value;
			}
		}
	=09
		public string Completion
		{
			get
			{
				return completion;
			}
			set
			{
				completion =3D value;
			}
		}
	=09
		public ArrayList Maintainers
		{
			get
			{
				return maintainers;
			}
			set
			{
				maintainers =3D value;
			}
		}
	=09
		public void AddMaintainer(string name)
		{
			maintainers.Add(name);
		}
	}
}

------=_NextPart_000_003E_01C1E1BA.CED66BD0
Content-Type: application/octet-stream;
	name="Status.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Status.cs"

/**
 * Namespace: com.mastergaurav.utils
 * Class:     Status
 *=20
 * Maintainer: mastergaurav@users.sourceforge.net
 * Name:       Gaurav Vaish
 * Status:     100%
 * Implementation: yes
 * Test-Suite: yes
 *=20
 * (C) Gaurav Vaish, 2001
 */

using System.IO;
using System;
using System.Collections;

namespace CSDOC.Utils
{
	public class Status
	{
		private string baseDir;
		private string statusFile;
		bool isDir;
		FileAttributes attrs;		// attribute of the baseDir
		ArrayList filesToRead;		// files to read
		//ArrayList listOfElements;	// data to write
		ClassElement currElem;		// the one that is being processed
		string[] mths =3D {
			"Jan",
			"Feb",
			"Mar",
			"Apr",
			"May",
			"Jun",
			"Jul",
			"Aug",
			"Sep",
			"Oct",
			"Nov",
			"Dec"
		};
	=09
		public Status(string baseDir, string statusFile)
		{
			this.baseDir =3D baseDir;
			if(baseDir=3D=3Dnull)
				return;
			try
			{
				attrs =3D File.GetAttributes(this.baseDir);
				isDir  =3D ((attrs & FileAttributes.Directory) =3D=3D =
FileAttributes.Directory);
				this.statusFile =3D ((statusFile=3D=3DString.Empty || =
statusFile=3D=3Dnull) ? "class.xml" : statusFile);
			} catch(Exception e)
			{
				this.baseDir =3D null;
				this.isDir =3D false;
				System.Console.WriteLine("Execption: {0}", e.ToString());
				return;
			}
		}
	=09
		public ArrayList GetFilesToRead()
		{
			if(this.baseDir=3D=3Dnull)
				return null;
			if(isDir)
				return GetFilesToRead(this.baseDir);
			return null;
		}

		//returns the name of the file where the data is stored
		public void GenerateStatusFile()
		{
			//System.Console.WriteLine("Writing in the file: {0}", statusFile);
			filesToRead =3D GetFilesToRead();
			StreamWriter writer;
			try
			{
				Stream stream =3D new FileStream(statusFile, FileMode.Truncate, =
FileAccess.Write);
				writer =3D new StreamWriter(stream);
			} catch(FileNotFoundException e)
			{
				writer =3D File.CreateText(statusFile);
			}
			writer.Write("<classes>\n");
			for(int i=3D0; i < filesToRead.Count; i++)
			{
				string fileName =3D (string)(filesToRead[i]);
				//System.Console.WriteLine("-----File: {0}-----", filesToRead[i]);
				currElem =3D ReadFromFile(fileName);
				//writer.Write("Alpha\r\n");
				if(currElem=3D=3Dnull)
					continue;
				writer.Write(currElem.GetXmlData("\t"));
				writer.Write("\n");
				writer.Flush();
			}
			writer.Write("</classes>");
			writer.Flush();
			writer.Close();
			//return statusFile;
		}
	=09
		private ClassElement ReadFromFile(string file)
		{
			Stream stream            =3D null;
			StreamReader reader      =3D null;
			ClassElement currElement =3D null;
			try
			{
				stream =3D new FileStream(file, FileMode.Open, FileAccess.Read);
				reader =3D new StreamReader(stream);
				if(reader.ReadLine().ToLower().IndexOf("exclude") >=3D0)
				{
					System.Console.WriteLine("Excluding {0}", file);
					stream.Close();
					reader.Close();
					return null;
				}
				string data;
				string val;
				int filled =3D 0x00;			// xxxx|impl|t_suit|compl|maints|
				string className =3D GetFullClassName(file);
				string l_act =3D ConvertToString(File.GetLastWriteTime(file));
				currElement =3D new ClassElement(className);
				currElement.LastActivity =3D l_act;
				while((data=3Dreader.ReadLine())!=3Dnull)
				{
					int isUseful =3D ParseLine(data, out val);
					if((isUseful<0) || ((filled & isUseful)!=3D0x00))
						continue;
					switch(isUseful)
					{
						case 0x01:	// Maintainer
									string[] all =3D val.Split(new Char[] {','});
									foreach(string mtr in all)
									{
										currElement.AddMaintainer(mtr.Trim());
									}
									break;
						case 0x02:	// Completion
									currElement.Completion =3D val;
									break;
						case 0x04:	// Test-Suite
									currElement.TestSuite =3D val;
									break;
						case 0x08:	// Implementation
									currElement.Implementation =3D val;
									break;
						default:	break;
					}
					filled |=3D isUseful;
					if((filled & 0x0F)=3D=3D0x0F)
					{
						break;
					}
				}
				stream.Close();
				reader.Close();
				if(currElement.IsAllSet())
					return currElement;
				else
					return null;
			}catch(Exception e)
			{
				System.Console.WriteLine("Exception: {0}", e.ToString());
			}
			if(stream!=3Dnull)
				stream.Close();
			if(reader!=3Dnull)
				reader.Close();
			return null;
		}
	=09
		private string GetFullClassName(string file)
		{
			file =3D file.Replace("\\","/");
			string nsDir =3D (Directory.GetParent(file)).ToString();			=
//namespace
			nsDir =3D nsDir.Replace("\\","/");
			string ns =3D nsDir.Substring(nsDir.LastIndexOf("/")+1);
			return (ns + "." + file.Substring(file.LastIndexOf("/")+1, =
file.LastIndexOf(".") - file.LastIndexOf("/")-1));
		}
	=09
		private int ParseLine(string data, out string val)
		{
			string[] spData;
			spData =3D data.Split(new Char[] {':'});
			int retVal =3D -1;
			if(spData.Length<2)
			{
				val =3D null;
				return -1;
			}
			spData[1] =3D spData[1].Trim();
			string temp =3D spData[0].ToLower().ToString();

			// xxxx|impl|t_suit|compl|maints|
			if(temp.IndexOf("maintainer")>=3D0)
			{
				retVal =3D 0x01;
			}
			if(temp.IndexOf("status")>=3D0 || temp.IndexOf("completion")>=3D0)
			{
				retVal =3D 0x02;
			}
			if(temp.IndexOf("test-suite")>=3D0)
			{
				retVal =3D 0x04;
			}
			if(temp.IndexOf("implementation")>=3D0)
			{
				retVal =3D 0x08;
			}
			val =3D spData[1];
			return retVal;
		}
	=09
		// Output is of the form: MMM-dd-yyyy
		private string ConvertToString(DateTime day)
		{
			return (mths[day.Month-1] + "-" + ((day.Day < 10) ? ("0" + =
day.Day.ToString()) : day.Day.ToString()) + "-" + day.Year);
		}
	=09
		private ArrayList GetFilesToRead(string dir)
		{
			string[] subDirs =3D Directory.GetDirectories(dir);
			string[] files =3D Directory.GetFiles(dir);
			ArrayList fList =3D new ArrayList();
		=09
			foreach(string sDir in subDirs)
			{
				// Don't go in the CVS files												=09
				if(!sDir.EndsWith("CVS") && !sDir.EndsWith("Test"))
				{
					ArrayList temp =3D GetFilesToRead(sDir);
					for(int i=3D0; i < temp.Count; i++)
						fList.Add(temp[i]);
				}
			}
			// Collect only the *.cs files
			foreach(string file in files)
			{
				if(file.EndsWith(".cs"))
				{
					fList.Add(file);
				}
			}
			return fList;
		}

		private bool IsDir(string dir)
		{
			return ((File.GetAttributes(dir) & FileAttributes.Directory) =3D=3D =
FileAttributes.Directory);
		}
	=09
		public static void Main(string[] args)
		{
			if(args.Length<1)
			{
				System.Console.WriteLine("Usage: Status <dir-name> =
[<status-file>]\n");
				return;
			}
		=09
			while(args[0].EndsWith("\\"))
				args[0] =3D args[0].Substring(0, args[0].Length - 1);

			string stFile =3D (args.Length>=3D2 ? args[1] : "");
			Status stat =3D new Status(args[0], stFile);
			System.Console.WriteLine("Total Files: {0}", =
stat.GetFilesToRead().Count);
			stat.GenerateStatusFile();
		}
	}
}

------=_NextPart_000_003E_01C1E1BA.CED66BD0--