From 7aaeab41ea0453aa86e17b815acb336a4067e2eb Mon Sep 17 00:00:00 2001 From: CNOCTAVE Date: Wed, 13 Nov 2024 16:22:40 +0800 Subject: [PATCH] update CI and doc --- .github/workflows/build-and-publish.yml | 24 +++++++++++++++ DESCRIPTION | 4 +-- NEWS | 4 +++ README.md | 4 +-- docs/{pic => }/banner0.png | Bin docs/index.html | 8 +++-- docs/{assets => }/main.css | 0 docs/{pic => }/translate_dropdown.png | Bin docs/{pic => }/translate_dropdown_code.png | Bin inst/tar_pack.m | 2 +- inst/tar_pack.py | 34 +++++++++++++++++---- inst/tar_unpack.m | 2 +- inst/tar_unpack.py | 31 ++++++++++++++++--- 13 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/build-and-publish.yml rename docs/{pic => }/banner0.png (100%) rename docs/{assets => }/main.css (100%) rename docs/{pic => }/translate_dropdown.png (100%) rename docs/{pic => }/translate_dropdown_code.png (100%) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..47289d9 --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,24 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Build and Publish + +on: + release: + types: [created] + +jobs: + linux-build: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + steps: + - uses: actions/checkout@v4 + with: + path: 'octave_tar' + # uncomment this on demand + # - run: sudo chmod a+x octave_tar/src/configure + # uncomment this on demand + - run: sudo chmod -R a+x octave_tar/inst + - run: tar --warning=no-file-changed --exclude='octave_tar/.git' --exclude='octave_tar/.github' -czvf octave_tar.tar.gz octave_tar + - run: gh release upload 1.0.1 octave_tar.tar.gz --repo $GITHUB_REPOSITORY diff --git a/DESCRIPTION b/DESCRIPTION index 36b39a1..1c2be56 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Name: octave_tar -Version: 1.0.0 -Date: 2024-11-07 +Version: 1.0.1 +Date: 2024-11-13 Author: various authors Maintainer: Yu Hongbo , CNOCTAVE Title: tar wrapper diff --git a/NEWS b/NEWS index f06302c..af76342 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ + ** v1.0.1 + Add CI build workflow. + Add document for extracting to current dir. +------------------------------------------------------- ** v1.0.0 Add document website. Add bug tracker website. diff --git a/README.md b/README.md index f34d1cc..1e8cdc9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ 2. Translate en-US.html into English. 3. Add dropdown like the picture below to every *.html. For example, add dropdown "en-US English". - ![the dropdown looking](./docs/pic/translate_dropdown.png) + ![the dropdown looking](./docs/translate_dropdown.png) The code for adding dropdown is like the picture below. - ![the dropdown code](./docs/pic/translate_dropdown_code.png) + ![the dropdown code](./docs/translate_dropdown_code.png) 4. PR to octave_tar. \ No newline at end of file diff --git a/docs/pic/banner0.png b/docs/banner0.png similarity index 100% rename from docs/pic/banner0.png rename to docs/banner0.png diff --git a/docs/index.html b/docs/index.html index 444c68f..0446861 100644 --- a/docs/index.html +++ b/docs/index.html @@ -25,7 +25,7 @@ - + octave_tar文档 @@ -143,7 +143,7 @@
- +
octave_tar文档
@@ -158,7 +158,7 @@
在线安装

octave_tar可以在线安装。

在线安装octave_tar,代码如下:
-

>> pkg install 'https://github.com/CNOCTAVE/octave_tar/releases/download/1.0.0/octave_tar.tar.gz'

+

>> pkg install 'https://github.com/CNOCTAVE/octave_tar/releases/download/1.0.1/octave_tar.tar.gz'

源码安装

octave_tar可以直接使用tar包安装。

@@ -193,6 +193,8 @@

>> tar_pack("file", "dir", "new.tar")

解包一个名为file.tar的文件至new_file文件夹,代码如下:

>> tar_unpack("file.tar", "new_file")

+
解包一个名为file.tar的文件至当前文件夹,代码如下:
+

>> tar_unpack("file.tar", ".")

引用octave_tar
如果你在学术研究中涉及octave_tar,那么可以按需引用以下内容。
diff --git a/docs/assets/main.css b/docs/main.css similarity index 100% rename from docs/assets/main.css rename to docs/main.css diff --git a/docs/pic/translate_dropdown.png b/docs/translate_dropdown.png similarity index 100% rename from docs/pic/translate_dropdown.png rename to docs/translate_dropdown.png diff --git a/docs/pic/translate_dropdown_code.png b/docs/translate_dropdown_code.png similarity index 100% rename from docs/pic/translate_dropdown_code.png rename to docs/translate_dropdown_code.png diff --git a/inst/tar_pack.m b/inst/tar_pack.m index 1eb7c6d..68027d3 100644 --- a/inst/tar_pack.m +++ b/inst/tar_pack.m @@ -29,5 +29,5 @@ if nargin < 2 print_usage(); endif - [ret, status] = python("tar_pack.py", varargin{:}) + [ret, status] = python("tar_pack.py", varargin{:}); end \ No newline at end of file diff --git a/inst/tar_pack.py b/inst/tar_pack.py index a040154..584ffa5 100644 --- a/inst/tar_pack.py +++ b/inst/tar_pack.py @@ -17,6 +17,25 @@ import sys import tarfile import os +import warnings +from builtins import UserWarning + +class output(UserWarning): + pass + +def custom_warning_format(message, category, filename, lineno, file=None, line=None): + formatted_message = f"{category.__name__}: {message}" + print(formatted_message, end='\n') + +# 设置自定义的警告显示处理函数 +warnings.showwarning = custom_warning_format + +def print_log(message, category=output, stacklevel=1, source=None): + """Logger function. + 1. You cannot call print() to directly print to Octave terminal. + 2. Octave package doesn't allow to make deeper Python package dir. + So use this instead.""" + warnings.warn(message, category, stacklevel, source) if len(sys.argv) < 3: print("Usage: tar_pack(source1, source2, ... , output_filename)") @@ -25,12 +44,15 @@ def tar_directory(source_list_output_filename): source_list = source_list_output_filename[:-1] output_filename = source_list_output_filename[-1] - - - with tarfile.open(output_filename, "w:") as tar: - for path in source_list: - tar.add(path, arcname=os.path.basename(path)) - print(f"Source {path} has been tarred to {output_filename}.") + try: + with tarfile.open(output_filename, "w:") as tar: + for path in source_list: + tar.add(path, arcname=os.path.basename(path)) + print_log(f"Source {path} has been tarred to {output_filename}.") + return 0 + except BaseException as e: + print_log(e) + return 1 if __name__ == "__main__": tar_directory(sys.argv[1:]) \ No newline at end of file diff --git a/inst/tar_unpack.m b/inst/tar_unpack.m index c99a0c2..aefda4f 100644 --- a/inst/tar_unpack.m +++ b/inst/tar_unpack.m @@ -29,5 +29,5 @@ if nargin < 2 print_usage(); endif - [ret, status] = python("tar_unpack.py", tar_filename, destination_dir) + [ret, status] = python("tar_unpack.py", tar_filename, destination_dir); end \ No newline at end of file diff --git a/inst/tar_unpack.py b/inst/tar_unpack.py index b94448a..47336f4 100644 --- a/inst/tar_unpack.py +++ b/inst/tar_unpack.py @@ -17,6 +17,25 @@ import sys import tarfile import os +import warnings +from builtins import UserWarning + +class output(UserWarning): + pass + +def custom_warning_format(message, category, filename, lineno, file=None, line=None): + formatted_message = f"{category.__name__}: {message}" + print(formatted_message, end='\n') + +# 设置自定义的警告显示处理函数 +warnings.showwarning = custom_warning_format + +def print_log(message, category=output, stacklevel=1, source=None): + """Logger function. + 1. You cannot call print() to directly print to Octave terminal. + 2. Octave package doesn't allow to make deeper Python package dir. + So use this instead.""" + warnings.warn(message, category, stacklevel, source) if len(sys.argv) < 3: print("Usage: tar_unpack(tar_filename, destination_dir)") @@ -34,10 +53,14 @@ def untar_file(tar_filename, destination_dir): if not os.path.exists(destination_dir): os.makedirs(destination_dir) - with tarfile.open(tar_filename, "r:") as tar: - tar.extractall(path=destination_dir) - - print(f"File {tar_filename} has been untarred to {destination_dir}.") + try: + with tarfile.open(tar_filename, "r:") as tar: + tar.extractall(path=destination_dir) + print_log(f"File {tar_filename} has been untarred to {destination_dir}.") + return 0 + except BaseException as e: + print_log(e) + return 1 if __name__ == "__main__": untar_file(sys.argv[1], sys.argv[2]) \ No newline at end of file