mirror of
https://github.com/sasjs/core.git
synced 2025-12-15 16:14:36 +00:00
feat(*): recreate library as scoped package
This commit is contained in:
128
meta/mm_updatestpsourcecode.sas
Normal file
128
meta/mm_updatestpsourcecode.sas
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
@file
|
||||
@brief Update the source code of a type 2 STP
|
||||
@details Uploads the contents of a text file or fileref to an existing type 2
|
||||
STP. A type 2 STP has its source code saved in metadata.
|
||||
|
||||
Usage:
|
||||
|
||||
%mm_updatestpsourcecode(stp=/my/metadata/path/mystpname
|
||||
,stpcode="/file/system/source.sas")
|
||||
|
||||
|
||||
@param stp= the BIP Tree folder path plus Stored Process Name
|
||||
@param stpcode= the source file (or fileref) containing the SAS code to load
|
||||
into the stp. For multiple files, they should simply be concatenated first.
|
||||
@param minify= set to YES in order to strip comments, blank lines, and CRLFs.
|
||||
|
||||
@param frefin= change default inref if it clashes with an existing one
|
||||
@param frefout= change default outref if it clashes with an existing one
|
||||
@param mDebug= set to 1 to show debug messages in the log
|
||||
|
||||
@version 9.3
|
||||
@author Allan Bowe
|
||||
|
||||
**/
|
||||
|
||||
%macro mm_updatestpsourcecode(stp=
|
||||
,stpcode=
|
||||
,minify=NO
|
||||
,frefin=inmeta
|
||||
,frefout=outmeta
|
||||
,mdebug=0
|
||||
);
|
||||
/* first, check if STP exists */
|
||||
%local tsuri;
|
||||
%let tsuri=stopifempty ;
|
||||
|
||||
data _null_;
|
||||
format type uri tsuri value $200.;
|
||||
call missing (of _all_);
|
||||
path="&stp.(StoredProcess)";
|
||||
/* first, find the STP ID */
|
||||
if metadata_pathobj("",path,"StoredProcess",type,uri)>0 then do;
|
||||
/* get sourcecode */
|
||||
cnt=1;
|
||||
do while (metadata_getnasn(uri,"Notes",cnt,tsuri)>0);
|
||||
rc=metadata_getattr(tsuri,"Name",value);
|
||||
put tsuri= value=;
|
||||
if value="SourceCode" then do;
|
||||
/* found it! */
|
||||
rc=metadata_getattr(tsuri,"Id",value);
|
||||
call symputx('tsuri',value,'l');
|
||||
stop;
|
||||
end;
|
||||
cnt+1;
|
||||
end;
|
||||
end;
|
||||
else put (_all_)(=);
|
||||
run;
|
||||
|
||||
%if &tsuri=stopifempty %then %do;
|
||||
%put WARNING: &stp.(StoredProcess) not found!;
|
||||
%return;
|
||||
%end;
|
||||
|
||||
%if %length(&stpcode)<2 %then %do;
|
||||
%put WARNING: No SAS code supplied!!;
|
||||
%return;
|
||||
%end;
|
||||
|
||||
filename &frefin temp lrecl=32767;
|
||||
|
||||
/* write header XML */
|
||||
data _null_;
|
||||
file &frefin;
|
||||
put "<UpdateMetadata><Reposid>$METAREPOSITORY</Reposid>
|
||||
<Metadata><TextStore id='&tsuri' StoredText='";
|
||||
run;
|
||||
|
||||
/* escape code so it can be stored as XML */
|
||||
/* write contents */
|
||||
%if %length(&stpcode)>2 %then %do;
|
||||
data _null_;
|
||||
file &frefin mod;
|
||||
infile &stpcode lrecl=32767;
|
||||
length outstr $32767;
|
||||
input outstr ;
|
||||
/* escape code so it can be stored as XML */
|
||||
outstr=tranwrd(_infile_,'&','&');
|
||||
outstr=tranwrd(outstr,'<','<');
|
||||
outstr=tranwrd(outstr,'>','>');
|
||||
outstr=tranwrd(outstr,"'",''');
|
||||
outstr=tranwrd(outstr,'"','"');
|
||||
outstr=tranwrd(outstr,'0A'x,'
');
|
||||
outstr=tranwrd(outstr,'0D'x,'
');
|
||||
outstr=tranwrd(outstr,'$','$');
|
||||
%if &minify=YES %then %do;
|
||||
outstr=cats(outstr);
|
||||
if outstr ne '';
|
||||
if not (outstr=:'/*' and subpad(left(reverse(outstr)),1,2)='/*');
|
||||
%end;
|
||||
outstr=trim(outstr);
|
||||
put outstr ' ';
|
||||
run;
|
||||
%end;
|
||||
|
||||
data _null_;
|
||||
file &frefin mod;
|
||||
put "'></TextStore></Metadata><NS>SAS</NS><Flags>268435456</Flags>
|
||||
</UpdateMetadata>";
|
||||
run;
|
||||
|
||||
|
||||
filename &frefout temp;
|
||||
|
||||
proc metadata in= &frefin out=&frefout;
|
||||
run;
|
||||
|
||||
%if &mdebug=1 %then %do;
|
||||
/* write the response to the log for debugging */
|
||||
data _null_;
|
||||
infile &frefout lrecl=32767;
|
||||
input;
|
||||
put _infile_;
|
||||
run;
|
||||
%end;
|
||||
|
||||
%mend;
|
||||
Reference in New Issue
Block a user