`
ticojj
  • 浏览: 156510 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

project_rename

 
阅读更多

#!/bin/ksh
# $Header: $
# $Modtime:$
################################################################################
# COPYRIGHT.  HANG SENG BANK LIMITED 2013.  ALL RIGHTS RESERVED.
# NO PART OF THIS PUBLICATION MAY BE REPRODUCED, STORED IN A RETRIEVAL SYSTEM,
# OR TRANSMITTED, ON ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,
# PHOTOCOPYING, RECORDING, OR OTHERWISE, WITHOUT THE PRIOR WRITTEN PERMISSION
# OF HANG SENG BANK LIMITED.
#
# Filename      : projectx_rename (shell script file)
#
# Author        : Luffy Cao
#
# Abstract      : Check the Trade reports delivery signal of Bank level
#
# Modification History :
#
# Version       Date            Author          Description
#-------------  --------------  --------------- ------------------------------
# 1.0           26 Jun 2013     Luffy Cao       Initial Creation
#
##############################################################################
rootpath=$0
cd "${rootpath%/*}"
file=`echo $0 | cut -d'/' -f5`

# The report file (pdf, html, etc) to be renamed
param_src_file=$1

# The corresponding XML file containing information for renaming
param_xml_file=$2


#set up path
log_path=`awk NR==2 ../JobSch.ini | cut -f1`
raw_path=`awk NR==3 ../JobSch.ini | cut -f1`
report_path=`awk NR==17 ../JobSch.ini | cut -f1`

#set up log file and date file
log_file_1=$log_path/${file}_1.log
log_file_2=$log_path/${file}_2.log
date_file=$report_path/projectx_date.txt

echo "Start to execute "$file" ..."

#Create log file
createLogfile()
{
echo "" > $1
}


#xpath function for XML parsing
xpath()
{
echo "cat $1" | xmllint --shell $2 | sed '/^\/ >/d'
}

#Get content of tag from XML file
getContent()
{
 xmlcode=$1
 checktag=$2
 content=`xpath "//*[local-name()='outputDescriptor']/*[local-name()='$checktag']/text()" $xmlcode`
 echo $content
}

#Get value from content of tag in XML file
getValue()
{
 xmlcontent=$1
 checkstr=$2
 found=1
 count=2
 value=""
 while [ $found -ne 0 ]
 do
  valuetmp=`echo "$xmlcontent" |awk -F \/ '{ print $'$count' }' | sed -r "s/(\[|\]|')//g"`
  if [[ $valuetmp == $checkstr* ]]
  then
   value=$valuetmp
   found=0
  else if [ -z "$valuetmp" ]
    then break
    fi
  fi
  count=$(( $count + 1 ))
 done
 echo $value
}
#Get name
getName()
{
 bfrenm=$1
 afrenm=`echo "$bfrenm" |awk -F = '{ print $2 }'`
 echo $afrenm
}


#Compare strings
checkStr()

 str1=$1
    str2=$2
 if [ "$str1" = "$str2" ]
 then
  return 0
 else
  return 1
 fi
}

# check xml package name
isPackage()
{
 xmlsource=$1
 pkgname=$2
 strContent=$(getContent $xmlsource reportSearchPath)
 szpkg=$(getValue "$strContent" "package")
 finalpkgnm=$(getName "$szpkg" )
 #Compare
 checkStr "$pkgname" "$finalpkgnm"
 checkStrcode=`echo $?`
 return $checkStrcode
}

#Rename pdf file
getNewName()
{
 xmlsource=$1
 nName="Unknown Report (PROJECTX)"
 strContent=$(getContent $xmlsource reportViewSearchPath)
 #validRpt=$(getValue "$strContent" "folder")
 #vaildRpt2=$(getName "$validRpt")
 nametmp=$(getValue "$strContent" "reportView")
 #if [ "$vaildRpt2" = "Generated Reports" ]
 #then
  if [ -z "$nametmp" ]
  then
   echo "reportView not found."   
  else
   nName=$(getName "$nametmp")
  fi
 #fi
 echo $nName
}

#copy file and put it to /REPORT
moveFile()
{
 oldpdf=$1
 newpdf=$2
 ext=$3
 if [[ "$oldpdf" == *\.$ext ]]
 then mv $raw_path/$oldpdf $report_path/$newpdf
 fi
}

#create dummy control files
CreateControlFile()
{
 ctlname=$1".ctl"
 content=$2
 echo $content > $report_path/$ctlname
 
 #change group permissions
 [ -f $report_path/$ctlname ] && { chgFileGroupAccess $report_path/$ctlname; }
}

# Change File Group Access
chgFileGroupAccess ()
{
   outfilename=$1
   chgrp cogmap_jbsrun $outfilename
   chmod g+rw $outfilename
}

#Create execution control file
CreateEXEControlFile()
{
 ctlexename=$1".txt"
 content1=$2
 content2=$3
 echo $content1 > $report_path/$ctlexename
 echo $content2 >> $report_path/$ctlexename
}

#Get verDate
getVerDate()
{
 xmlsource=$1
 verdte="Unknown Date"
 verdte=`xpath "//*[local-name()='outputDescriptor']/*[local-name()='parameterValues']/*[local-name()='item']/*[local-name()='name'][text()='Ver Date']/../*[local-name()='value']/*[local-name()='item']/*[local-name()='display']/text()" $xmlsource`
 echo $verdte
 }

#write verdate txt file
writeDateFile()
{
 verdte=$1
 echo $verdte > $date_file
 
}

#housekeeping remove xml after renaming
removeXML()
{
 xmlfile=$1
 rm -f $xmlfile
}

#Get log file name
getLogFileName()
{
 reminder=`echo "\`date +%m\`%2" | bc`
 if [ $reminder -ne 0 ]
 then
  echo "1"
 else
  echo "2"
 fi
 
}

#Reset log file if now month
tryResetLog()
{
 resetLog=1
 logfile=$1
 logNum=$2
 if [ -f $logfile ]
 then
 modMonth=`echo \`ls -l $logfile\` | awk '{print $6}'`
 nowMonth=`echo \`date +%b\``

  if [ "$modMonth" = "$nowMonth" ]
  then
   resetLog=0
  fi
 else
  resetLog=0
  createLogfile $1
 fi
 
 if [ $resetLog -eq 1 ]
 then
  rm -f $logfile         
  createLogfile $1
 fi
}

getExtension()
{
 source=$1
 getext=`echo "$source" |awk -F \. '{ print $2 }'`
 [ "$getext" = "mht" ] && { getext="xls" ;}
 echo $getext
 
}

getDataRdyStus()
{
 xmlsource=$1
 getDataRdyStus="Unknown Status"
 getDataRdyStus=`xpath "//*[local-name()='outputDescriptor']/*[local-name()='parameterValues']/*[local-name()='item']/*[local-name()='name'][text()='Data Ready Status']" $xmlsource`
 [ -z $getDataRdyStus ] && { status="N"; } || { status="Y" ;}
 echo $status

 
}

# for f in `ls $raw_path/*.xml`
# do

 starttime=`date`
 xmlfilename=`basename $param_xml_file`
 LogFileNum=$(getLogFileName)
 
 if [ $LogFileNum = 1 ]
 then 
  tryResetLog $log_file_1 $LogFileNum 
  LogFileName=$log_file_1
 else 
  tryResetLog $log_file_2 $LogFileNum 
  LogFileName=$log_file_2
 fi


 if [ ! -f $param_xml_file ]; then
  echo "$param_xml_file not exists." | tee -a $LogFileName
  exit 1
 fi

 pdffilepath=$(getContent $param_xml_file fileName)

  
  echo "************************************"  | tee -a $LogFileName
  echo "Date: "$starttime       | tee -a $LogFileName
  echo "Parsing XML: "$xmlfilename     | tee -a $LogFileName
  echo "Original PDF: "$pdffilepath    | tee -a $LogFileName
  
  # xml reture error code
  xmlretcode=`echo $?`
  
  if [ $xmlretcode -ne 0 ]
  then 
    
    echo "Fail to parse xml file "$xmlfilename    | tee -a $LogFileName
    exit $xmlretcode
  else
    echo "Start Parse XML file "$xmlfilename   | tee -a $LogFileName
    isPackageretcode=1
    isPackage $param_xml_file "ProjectX"
    isPackageretcode=`echo $?`
    echo "isPackageretcode:$isPackageretcode --new added "  | tee -a $LogFileName
    if [ $isPackageretcode -eq 0 ]
    then
     echo "File belongs to PROJECTX"     | tee -a $LogFileName
     newName=$(getNewName $param_xml_file)
     if [[ $newName == *"Unknown Report (PROJECTX)"* ]]
     then
      echo "$newName, File skipped."    | tee -a $LogFileName
     else
      fileext=$(getExtension $pdffilepath)
      fullnewName=$newName"."$fileext
      echo "Parsed New File Name: "$fullnewName  | tee -a $LogFileName      
      rptVerDte=$(getVerDate $param_xml_file)
      echo "Report Version Date: "$rptVerDte   | tee -a $LogFileName
      #if [[ -z $rptVerDte || "$rptVerDte" = "Unknown Date" ]]
      #then
       #echo "Invalid Date String: [" $rptVerDte "]" | tee -a $LogFileName
      #else
       echo "Output Date String: [" $rptVerDte "]"  | tee -a $LogFileName
       #moveFile $pdffilepath $fullnewName $fileext
       
       #if [[ "$pdffilepath" == *\.$fileext ]]; then
        mv $raw_path/$pdffilepath $report_path/$fullnewName
        echo "Copy XML File to report parth." | tee -a $LogFileName
        ret1=`echo $?`
        if [ $ret1 -ne 0 ]; then
          echo "Failed to move $raw_path/$pdffilepath $report_path/$fullnewName" | tee -a $LogFileName
          exit 1
        fi
       #fi
       
       # change group
       [ -f $report_path/$fullnewName ] && { chgFileGroupAccess $report_path/$fullnewName; }
       
       # Create dummy control file
       CreateControlFile $newName ""
       
       # Create execution control file for LN
       #CreateEXEControlFile $newName "Y" $rptVerDte
       #writeDateFile $rptVerDte
       removeXML $param_xml_file       
      #fi
     fi
    else
     echo "File does not belong to PROJECTX"    | tee -a $LogFileName
    fi
  fi
#done

# reture error code
# retcode=`echo $?`
# if [ $retcode -ne 0 ]
# then
        # echo "Fail to execute "$file         | tee -a $LogFileName
        # exit $retcode
# fi

echo "Successful execution of "$file        
exit 0

分享到:
评论

相关推荐

    To-rename-the-project_-You-can-rename-the-project_The Good Proje

    it is good for KETAB and many other people

    VC Rename 更改工程名

    其中,设置文件如".dsp"(Digital Studio Project)和".dsw"(Digital Studio Workspace)包含了项目配置、依赖关系和编译设置等关键信息。更改工程名不仅涉及到工程文件的重命名,还需要更新所有引用到原工程名的...

    project-tornado

    rename base dir name `project-tornado` to you `project_name`.1. find all "project_tornado" replace to `you project_name`2. rename folders "project_tornado" to you `project_name`3. find all ...

    pythonProject3_命名规则_python_

    本项目"pythonProject3_命名规则_python_"专注于使用Python来实现文件的批量重命名,遵循特定的自定义规则。这涉及到Python的基础知识、文件操作和字符串处理技巧。 1. **Python基础知识**: - **变量**:在Python...

    VC工程重命名工具 VC Project Rename

    重命名VC工程的小工具,有时候以前写的VC程序需要重命名一下,使用这个工具可以很方便的修改VC工程里的各个文件为新名称。 程序支持从资源管理器直接拖放VC工程文件到程序窗口。

    Project7_学生信息_源码

    File对象提供了很多方法,如exists()检查文件是否存在,createNewFile()创建新文件,delete()删除文件,以及renameTo()重命名文件等。 4. 字符流与编码 - BufferedReader和PrintWriter:在这个项目中,我们可能会...

    log4j:ERROR Failed to rename错误解决办法

    在Tomcat6下使用Log4j记录日志,...网上查找了下原因,大概意思是日志文件始终被占有,所以当log4j对日志文件进行rename时,就发生了Failed to rename错误 。要修改log4j的源码,附件是我修改好后的,方便大家下载使用

    Rename an Existing Visual Studio project

    标题提到的"Rename an Existing Visual Studio project"是一个关于如何更改已创建的VS项目名称的主题。这个过程涉及到对项目文件、解决方案文件以及引用等多方面的修改,以确保重命名后的项目能够正常运行。 首先,...

    keil常用脚本.zip

    例如,文件名可能由原本的`project.hex`变为`project_2022-08-16.hex`,这样我们可以快速识别出哪个是最新或者特定日期的编译结果。 2. **z_del.bat**: 此脚本的功能是删除具有bin和hex后缀的文件。在开发过程中...

    unrxlib_275_u_1_0_13

    12/ rename parameter Name to AName in define event TExecOpenDialogEvent, because occur names conflict. 13/ repair conflict in string property in module RxTranslate for unicodes. 14/ some functions ...

    gcp-workload-identity-federation:Pypi模块可启用从AWS到GCP的工作负载身份联合,而无需静态证书

    # Rename example .env mv .env.example .env # Enter your own environment variables cat << EOF>.env export GCP_PROJECT_NUMBER= export GCP_PROJECT_ID= export GCP_WORKLOAD_ID= export GC

    delphixe10 RxLib_For_RX10插件

    12/ rename parameter Name to AName in define event TExecOpenDialogEvent, because occur names conflict. 13/ repair conflict in string property in module RxTranslate for unicodes. 14/ some functions ...

    RX Lib_For D5~XE2 XE3

    12/ rename parameter Name to AName in define event TExecOpenDialogEvent, because occur names conflict. 13/ repair conflict in string property in module RxTranslate for unicodes. 14/ some functions ...

    Windows环境下npm install 报错: operation not permitted, rename的解决方法

    前言 最近发现了一个问题,运行 npm ... Error: EPERM: operation not permitted, rename ‘/usr/share/nginx/html/tanteng.me/node_modules/duplexify' -> ‘/usr/share/nginx/html/tanteng.me/node_modules/.duple

    sap abap常用bapi

    6. BAPI_CHARACT_CREATE/BAPI_CHARACT_CHANGE/BAPI_CHARACT_DELETE/BAPI_CHARACT_RENAME/BAPI_CHARACT_GETDETAIL/BAPI_CHARACT_ADDLONGTEXT/BAPI_CHARACT_REMOVELONGTEXT/BAPI_CHARACT_GETLONGTEXT/CARD_...

    更改目录名源代码

    在提供的压缩包文件中,我们看到的文件如 `project1.exe` 是编译后的可执行文件,`project1.ico` 是应用程序图标,`unit1.lfm` 和 `unit1.pas` 分别是Lazarus的表单文件和对应的源代码文件,`project1.lpi`、`...

    Python代码重构的艺术:探索自动化重构工具

    renamer = Rename(project, resource) # 执行重命名操作 offset = 10 # 需要重命名的变量的偏移量 new_name = 'new_variable_name' renamer.do_rename(offset, new_name) ``` 2. **PyCharm**:使用PyCharm...

    mtdorb_1.0beta6

    Before build project rename file build.properties.pattern in build.properties and set specific for your machine parameters, then start build.bat (for Windows platform) or build.sh (for Linux)...

    解决git:fatal:Unable to create”…/.git/index.lock” 的错误

    问题描述: 在使用git 进行提交时, 出现上面这个报错, 导致...///Users/dianji/project/ccpay.h5/.git/index.lock是你的index.lock的目录, 通常直接复制报错信息里边的地址比较靠谱. 那这个index.lock有什么作用呢? 官

    gulp-starter-template:用于开发的 Gulp.js 入门模板

    Gulp 入门模板用于开发的 Gulp.js 入门模板。特征JavaScript 使用 uglify 压缩。 将 SCSS 文件编译为 CSS。 缩小和复制 CSS 文件。 当文件更改时,使用浏览器同步自动重新加载所有浏览器。...minify-css gulp-rename gu

Global site tag (gtag.js) - Google Analytics