Choose Language Hide Translation Bar
Highlighted
Georg
Level IV

How to enforce JMP to open a file in read only mode?

Dear all,

I use a method to update Addins like described in https://community.jmp.com/t5/JMP-Scripts/How-to-write-self-updating-JMP-add-ins/ta-p/21932/jump-to/f...  by @Jeff_Perkinson . There a file "metadata.jmp" Needs to be opened when JMP starts. I experienced some Problems with Opening this file automatically by many users, because under some circumstances a user might Keep that file opened for a Long time (without knowing this), and then I'm not able to update this files.

 

Also in other cases (large datatables shared by many users) it May be good to open files in Read only mode.

 

Is there a possibility to enforce JMP to open a data table etc. in Read only mode?

Georg
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
ih
ih
Level VII

Re: How to enforce JMP to open a file in read only mode?

I'm not sure how to open a file as read only (if anyone knows please chime in), but here are some ideas that might help you alleviate your issue:

  • Change file permissions so most users have read-only access to that file.
  • Make the section of code that needs the file open short and simple, and wrap it in a try block.  After the try block that handle the file operations, or in the catchExpr section, include code to close the file.  For example:
    try(
    	//Work with the file here
    	dt = Open("a file");
    	values = dt:Column << get values;
    	dt << Close;
    	
    ,	//This is the catchExpr, it is executed on an error.
    	
    	//Make sure the file is closed, but don't throw another if it wasn't open.
    	try( dt << Close ); 
    	
    	//Now raise an error.
    	throw( "Error working with metadata file: " || char( Exception_msg ) );
    );
    
    
    //Or you could close the file in a subsequent try function
    try(
    	//Work with the file here
    	dt = Open("a file");
    	values = dt:Column << get values;
    );
    try( dt << Close ); 
    
    
    //Now do any time consuming functions on the data extracted from that file
    //show(values);
      

View solution in original post

Highlighted
Georg
Level IV

Re: How to enforce JMP to open a file in read only mode?

@ih  thanks for your ideas, I will try to find a good working solution with it.

 

Setting permissions in filesystem is a straight Forward solution I would prefer, but Looking at it in Detail (files are on fileserver), I found many users to set the Rights for, and so it turned out to be complex. Because we have a few hundred users using the files, and I do not know under which users they act.

 

Just I got another idea:

- to copy the file to $TEMP and then open it

 

Georg

View solution in original post

8 REPLIES 8
Highlighted
ih
ih
Level VII

Re: How to enforce JMP to open a file in read only mode?

I'm not sure how to open a file as read only (if anyone knows please chime in), but here are some ideas that might help you alleviate your issue:

  • Change file permissions so most users have read-only access to that file.
  • Make the section of code that needs the file open short and simple, and wrap it in a try block.  After the try block that handle the file operations, or in the catchExpr section, include code to close the file.  For example:
    try(
    	//Work with the file here
    	dt = Open("a file");
    	values = dt:Column << get values;
    	dt << Close;
    	
    ,	//This is the catchExpr, it is executed on an error.
    	
    	//Make sure the file is closed, but don't throw another if it wasn't open.
    	try( dt << Close ); 
    	
    	//Now raise an error.
    	throw( "Error working with metadata file: " || char( Exception_msg ) );
    );
    
    
    //Or you could close the file in a subsequent try function
    try(
    	//Work with the file here
    	dt = Open("a file");
    	values = dt:Column << get values;
    );
    try( dt << Close ); 
    
    
    //Now do any time consuming functions on the data extracted from that file
    //show(values);
      

View solution in original post

Highlighted
Georg
Level IV

Re: How to enforce JMP to open a file in read only mode?

@ih  thanks for your ideas, I will try to find a good working solution with it.

 

Setting permissions in filesystem is a straight Forward solution I would prefer, but Looking at it in Detail (files are on fileserver), I found many users to set the Rights for, and so it turned out to be complex. Because we have a few hundred users using the files, and I do not know under which users they act.

 

Just I got another idea:

- to copy the file to $TEMP and then open it

 

Georg

View solution in original post

Highlighted
vince_faller
Super User

Re: How to enforce JMP to open a file in read only mode?

Could you just make your JMP table a csv?

Vince Faller - Predictum
Highlighted
Georg
Level IV

Re: How to enforce JMP to open a file in read only mode?

@vince_fallerthanks,  in my case a jmp table is preferred, I have a small table, that I Need to edit (by JMP).

 

In another case, when I would have large tables, that are used by many users, also a jmp table would be better, because conversion is not needed, wouldn't it?

Additionally the jmp table has more functionality (scripts, data types …), so I would Always prefer jmp table as filetype.

Georg
Highlighted
ih
ih
Level VII

Re: How to enforce JMP to open a file in read only mode?

A suggestion: the Add-in Manager that @Justin_Chilton created automates the method that @Jeff_Perkinson described.  The add-in updates a .jsl file containing an associative array which is read by users.

vince_faller
Super User

Re: How to enforce JMP to open a file in read only mode?

@Georg 
A few assumptions about your application. 

1. multiple people aren't writing to metadata simultaneously

2. it's a read-only call to "is there a new version of one of my apps?  Where is it?"


If both of those are true then I'd normally actually use a SQLite database and make ODBC calls to it.  I wouldn't say that there needs to be  a lot of bells and whistles if all you're doing is retrieving meta data.  Plus you could do stuff like actually store the addin in the database as well.  JMP tables are great for lots of things.  But for this specific application, I'd say it's overkill.  If it's just a throwaway call that you're going to close as soon as you see if there's a new version, .... 

You can still easily script it.  Again this wouldn't work well if multiple users are writing at the same time. The big thing is that when JMP opens a CSV it doesn't lock the original file like it does with a JMP table.  

 

Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");

csv_path = convert file path("$DESKTOP\Big Class.csv");
dt << Save As(csv_path);
close(dt, no save);
dt_csv = open(csv_path); 
dt_csv << Add Rows({:name = "Fake", :age = 14, :sex = "F", :height = 14, :weight = 28});
dt_csv:age[1] = 0;
// I can still delete this file even though I have the table open
show(delete file(csv_path));

dt_csv << Save As(csv_path);


I'd just generally go without the JMP table functionality than deal with multiple permissions levels.  Because if you open a csv in a JMP script, it opens a JMP table that isn't tied 

Vince Faller - Predictum
Highlighted
Craige_Hales
Staff (Retired)

Re: How to enforce JMP to open a file in read only mode?

Saving to disk as hidden or read-only has a RunProgram snippet to run the DOS attrib command. You can mark the file as read-only, or clear the flag.

Craige
Highlighted
Georg
Level IV

Re: How to enforce JMP to open a file in read only mode?

Thank you all for so much proposals, I'll try them out and will find a good solution.

Georg
Article Labels