0

Has anyone here got experience in building a parser for the MKS Integrity command line API. I am planning to build an API (in C#) and would need to build a CLI result parser which I could use to parse the results from the CLI. I have heard that the results from the CLI does not follow any specific data layout (there are no field separators etc.) and is subject to change from versions to versions. Is this true? I have heard about the JAVA and ANSI C api but have also heard that they don't support all the functionality exposed by the CLI. Any feedback will be of great help.

Thanks and Regards, Joe.

Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
Joe Varghese
  • 59
  • 1
  • 9

5 Answers5

2

Good luck. It's extremely difficult to parse MKS's output. For instance the "si viewsandbox" command indicates subproject structure by indentation. Here is a Perl code snippet to map members to subprojects:

our %parentproject;
our @projects;
my @subprojects;
$subprojects[0] = $sandbox;
$projects[0] = $sandbox;
open MKS, "si viewsandbox -R -S $sandbox |" or die $!;
while () {
    chomp;
    next if /working file/i;
    next if /new revision available/i;
    my ($indentation, $filename, $project, $version, $type);
    if (m:^( +)$dir/(.+) archived (.+) *$:) {
        ($indentation, $filename, $version) = ($1, $2, $3);
    }
    if (m:^( +)$dir/(.+project) (\((.+)\) )?(.*subsandbox) *$:) {
        ($indentation, $project, $version, $type) = ($1, $2, $4, $5);
    }
    next unless $indentation;
    my $level = length($indentation) / 2 + 1;
    if ($project) {
        $subprojects[$level] = $project;
        $parentproject{$project} = $subprojects[$level - 1];
        push @projects, $project;
    }
    if ($filename) {
        $parentproject{$filename} = $subprojects[$level - 1];
    }
}

This script runs on Linux, so folder separators are /. You may want to use \ in some regexps on Windows.

Please take time to appreciate the beauty of MKS' output. Direct members of the project indented by 1. Members of a subproject indented by 3. Members of a subproject of a subproject indented by 5. And so on.

I'd give up, and write ad hoc scripts where absolutely necessary, but no more. And yes, the output does change between versions. Sometimes.

SzG
  • 12,333
  • 4
  • 28
  • 41
1

Try the --xmlapi option with your commands and receive an answer in XML format.

Best regards,

Axel

Axel
  • 11
  • 1
  • Hi Axel, Could you please provide more info on this. Do you mean that PTC (MKS) client has an XML API, if so, could you please share which version you are referring to (and a sample cmd-line command). My API needs to support from PTC / MKS version 2009 on-wards. – Joe Varghese Nov 18 '13 at 13:58
0

@Joe Varghese, not sure if you are still working on this, but (on win7 with MKS Integrity 2009) I can do this sort of thing:

si memberinfo --xmlapi [file_name_goes_here]

Which will give you the output in XML:

<?xml version="1.0"?>
<Response command="memberinfo" app="si" version="4.10.0 7-1 9665">
  <App-Connection port="7001" userID="some_ID" server="some_server"></App-Connection>
  <WorkItems selectionType="IMemberSelection">
    <WorkItem id="some_path_to_a_file" context="c:/Groups/MKS/IntegrityServer/some_path_to_a_project.pj" displayId="some_path_to_a_file" modelType="si.Member">
      <Field name="membername">

...

You need to add these (or equivalent on your machine) to your windows PATH variable so it can see the MKS CLI commands:

C:\Program Files (x86)\MKS\IntegrityClient\bin;

C:\Program Files (x86)\MKS\Toolkit\mksnt;

Best of luck.

  • Thanks for the info. Yes, the xmlApi does provide a readable output, but as per MKS (PTC), the XmlApi is not officially supported. That's a risk we can't take. :( – Joe Varghese Jun 23 '15 at 12:36
0

keep in mind that not all commands are available either via CLI or java API (see some examples at the bottom)

it's a pity that as of PTC Integrity 10.5 you can't rely just in one of them to automate your activities.

it is also a pity that PTC Integrity doesn't provide much information about how stable is all this. I assume API is more stable (as in other tools).

so depending on your use cases, you might need to use CLI and --xmlapi option and parse the output (which is hell).

regarding C#, java, etc.. it is all up to you. the API is in Java, but you can of course call it from C#, Python, etc with proper wrappers. I am lately tending to use Groovy...

f.e. for PTC Integrity 10.5 in CM side (similar results you can have in IM side) here some commands available only via API and not via CLI:

  • projectadd
  • projectci
  • projectco

and here some commands available only via CLI and not via API :

  • acceptcp
  • addlabel
  • addmemberattr
  • addproject
  • addprojectlabel
  • addprojectmetric
  • applycp ... (81 in total)
YaP
  • 339
  • 3
  • 13
0

My solution for issues, types, fields, etc. was to parse the output, when I see a line with text that has no leading spaces but has a colon, it's a key:value pair. If the next line is leading whitespace, I could append, but I throw the output away including the previous line. Only lines that fit the standard key:value are directly parsed.

Then for those field names that I threw away, I'll do the following (the example here is as an issue):

im issues --fields='list,of,fieldnames' item# and then parse them separated by tabs. If your field may contain a tab, I fetch it individually with no other fields. Then I have a perl associative array with the key=value pairs.

I know this isn't the most efficient, but it does appear to accurately pull the fields for parsing.

I do have another function in perl I put together that reads type, field, query, presentations (as XML). It is a lot more complicated. Once I have it cleaned up more, I may come back to repost.