适用于计算机学院同学的作业目录管理系统

2024-04-22 12:08

本文主要是介绍适用于计算机学院同学的作业目录管理系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

摘要

对于计算机学院的同学(或其它院的同学),完成各种涉及程序设计的实验、作业、大作业、课程论文等可能已经是习以为常的事了。为每项作业建立目录、打包等工作虽然简单,但本着尽量将重复性劳动自动化以降低错误率和节省时间的原则,本文介绍了一种方法,通过充分利用构建工具 Apache Ant,实现作业目录的自动化管理。

基本作业目录结构

作业目录树的根目录名在本文中被称作${aid},其中 aid 是 assignment ID 的缩写,本人在使用此管理工具时常令根目录名为数字,表示第几次实验或作业。

通常一个作业目录树中包含以下几项文件或文件夹:

  • 报告文件夹(包含需要提交的实验报告、课程论文等)
  • 代码文件夹(包含作业中涉及的源代码,例如把整个 Eclipse 工程目录放在这里供老师参考)
  • 图片文件夹(包含程序截图、硬件连接图例、照片等)

对应于本实现中的目录名为:

  • report
  • project
  • pic

除此以外,可能还会包含参考资料文件夹等,不过个人觉得以上三个文件夹是通常而言必不可少的基本目录结构。

目录管理需要实现的功能

作为一个实用的作业目录管理工具,需要实现以下功能:

  • 创建基本目录结构(创建如上所述的基本目录结构,避免一个个手动建文件夹)
  • 发布用于交作业的压缩包(包含必要的运行前检查,如报告是否存在;以及自动按正确命名格式生成压缩包)
  • 清除发布与备份(将已存在的压缩包转为备份格式,并清除所有中间文件)
  • 导出作业目录(将作业目录整个复制到可移动存储介质上,例如用于放到学校机房电脑上完成作业)
  • 导入作业目录(将作业目录从可移动存储介质上导入或更新到本地,例如用于在机房完成作业后迁移或本地磁盘的过程)

对应于本实现中的功能名为:

  • make
  • dist
  • clean-dist
  • export
  • import

本实现中所需要的外部属性

为增强目录管理功能的通用性,本实现中将基本功能放到根构建文件中,而把需要定制的部分放到其它构建文件,并在那里调用根构建文件。根构建文件需要一些外部属性(property)以实现其可定制性。

  • aid:根目录名,必需的外部属性
  • report.name:报告名(包含扩展名),管理工具需要知道报告名以在发布前检查报告文件夹中是否存在以此命名的文件;在做发布清除发布 操作时需要用到
  • dist.arc.name:交作业压缩包名,需要以 .zip 为扩展名,因为本实现使用 zip 格式进行压缩;在做发布清除发布 操作时需要用到
  • ext.dir:可移动存储介质路径,在做导入导出 操作时需要用到

这些外部属性可以在构建文件中调用根构建文件前通过 property 任务指定,也可在命令行中通过 -D 选项指定。例如:

ant -Daid=2 make

创建了一个根目录名为“2”的作业目录(如果重名文件夹不存在),此处指定外部属性 aid 值为“2”。

根构建文件使用方法

<ant antfile="${root-buildfile}" target="${target-to-invoke}" />

调用了所处路径为 ${root-buildfile} 的根构建文件中名为 ${target-to-invoke} 目标。

运行效果

假设根构建文件的全路径被 root-buildfile 属性指定,假设所有被管理的作业文件夹所处的目录(被称作“作业库”)中除它们自己外有且只有可定制的构建文件 build.xml。在此处以根目录名为“3”的作业文件夹为例。

作业库初始状态

init.jpg

创建基本目录

ant -Daid=3 make

after-make_1.jpg

这是作业库的样子。

after-make_2.jpg

这是作业目录“3”内部的样子。

完成作业

模拟了插入截图和写完报告的过程,源代码部分未模拟。

before-dist_1.jpg

这是pic目录中的内容。

before-dist_2.jpg

这是report目录中的内容。

发布

ant -Daid=3 dist

after-dist_1.jpg

这是发布后作业目录“3”内部的样子,其中dist目录是临时文件夹,包含压缩包中的内容,如果不删除,那么修改后再次发布时用时会更短一些。压缩包的名字需要在定制的构建文件中指定。

after-dist_2.jpg

这是压缩包内部的样子,因为没有往project(代码文件夹)中放东西,所以没有将其包含在压缩包内。如果在发布时没有往report(报告文件夹)中放入名为“Lab3 Report.docx”的报告(此名称需要在定制的构建文件中指定),那么会报错“report not found”。

after-dist_3.jpg

这是压缩包中pic文件夹内部的样子。

清除发布

ant -Daid=3 clean-dist

after-clean-dist.jpg

这是作业目录“3”内部的样子,dist文件夹被删除了,而且压缩包被加了bak后缀转成了备份文件的形式,该文件会在下一次发布前删除。

导入导出 功能就不展示了,没什么直观效果。


附录

附录中记录了构建文件代码,使用的是 Apache Ant 1.9.7。

根构建文件

<project name="assignment-mgmt"><!-- External property: name="aid", type="int" required="true" --><!-- External property: name="report.name" type="str" required="true for target dist" --><!-- External property: name="dist.arc.name" type="str" required="true for target dist" --><!-- External property: name="ext.dir" type="location" required="true for target export, import" --><description>Simplify the assignment file management.The directory template for each assignment directory is such:root directory| report             [DIRECTORY]| project            [DIRECTORY]| pic                [DIRECTORY]| dist               [DIRECTORY]| ${dist.arc.name}   [FILE]wherereport        - directory for reportsproject       - directory for source codespic           - directory for snapshots, photos, etcdist          - temporary directory for holding submission files;appear only after target &quot;dist&quot;${dist.arc.name} - an archive file for submissionThe &quot;dist&quot; folder as well as the final archive contain thefollowing contents:* project directory unless it's empty* pic directory unless it's empty* the report file specified in external properties under the reportdirectoryExternal properties required:aid           - assignment_id, required by all targetsreport.name   - report name, required by target &quot;dist&quot;dist.arc.name - the name of zip archive, required by target&quot;dist&quot;ext.dir       - external directory, esp portable device, to temporarilyaccommodate the assignment directory, required bytarget &quot;import&quot; and &quot;export&quot;</description><!-- main directory names --><property name="report.dir.name" value="report" /><property name="proj.dir.name" value="project" /><property name="pic.dir.name" value="pic" /><!-- directory locations --> <property name="dist.dir" location="${aid}/dist" /><!-- temporary --><property name="report.dir" location="${aid}/${report.dir.name}" /><property name="proj.dir" location="${aid}/${proj.dir.name}" /><property name="pic.dir" location="${aid}/${pic.dir.name}" /><!--Public targets--><target name="make" depends="-extvar-check" description="make &quot;${aid}&quot; assignment directories"><mkdir dir="${aid}" /><mkdir dir="${report.dir}" /><mkdir dir="${proj.dir}" /><mkdir dir="${pic.dir}" /></target><target name="dist" depends="-extvar-check-dist,-check-report-availability" description="distribute the assignment under directory &quot;${aid}&quot; before removing the backup version of previous build if any"><delete file="${aid}/${dist.arc.name}.bak" failonerror="false" /><mkdir dir="${dist.dir}" /><copy todir="${dist.dir}" includeemptydirs="false"><fileset dir="${report.dir}"><include name="${report.name}" /></fileset><fileset dir="${aid}"><include name="${pic.dir.name}/**" /><include name="${proj.dir.name}/**" /></fileset></copy><zip destfile="${aid}/${dist.arc.name}" basedir="${dist.dir}" update="true" /></target><target name="clean-dist" depends="-extvar-check-dist" description="clean distribution of assignment under directory &quot;${aid}&quot; but leave a backup version of original distributed archive intact"><delete dir="${dist.dir}" /><move file="${aid}/${dist.arc.name}" tofile="${aid}/${dist.arc.name}.bak" /></target><target name="export" depends="-extvar-check-export" description="export assignment directory &quot;${aid}&quot; to directory specified by property &quot;ext.dir&quot;"><mkdir dir="${ext.dir}/${aid}" /><copy todir="${ext.dir}/${aid}"><fileset dir="${aid}" /></copy></target><target name="import" depends="-extvar-check-import" description="import/update assignment directory &quot;${aid}&quot; from directory &quot;${ext.dir}/${aid}&quot; specified by property &quot;ext.dir&quot;"><copy todir="${aid}"><fileset dir="${ext.dir}/${aid}" /></copy></target><!--Auxilliary targets--><!-- ensure all basic external properties necessary are available, and fail the build otherwise --><target name="-extvar-check"><!-- condition on external property "aid" --><condition property="aid.available"><isset property="aid" /></condition><fail unless="aid.available">external property "aid" required yet not found</fail></target><!-- ensure all external properties required by target &quot;dist&quot; are available, and fail the build otherwise --><target name="-extvar-check-dist" depends="-extvar-check"><!-- condition on external property "report.name" --><condition property="report.name.available"><isset property="report.name" /></condition><fail unless="report.name.available">external property "report.name" required yet not found</fail><!-- condition on external property "dist.arc.name" --><condition property="dist.arc.name.available"><isset property="dist.arc.name" /></condition><fail unless="dist.arc.name.available">external property "dist.arc.name" required yet not found</fail></target><!-- ensure report file is available before distribution --><target name="-check-report-availability"><!-- condition on the availability of the report file --><available property="report.available" file="${report.dir}/${report.name}" type="file" /><fail unless="report.available">report "${report.name}" not found under "${report.dir}"</fail></target><!-- ensure all external properties required by target &quot;import&quot; and &quot;export&quot; are available, and fail the build otherwise --><target name="-extvar-check-import-export" depends="-extvar-check"><!-- condition on external property "ext.dir" --><condition property="ext.dir.available"><isset property="ext.dir" /></condition><fail unless="ext.dir.available">external property "ext.dir" required yet not found</fail></target><!-- ensure all external properties required by target &quot;import&quot; are available and valid, and fail the build otherwise --><target name="-extvar-check-import" depends="-extvar-check-import-export"><!-- condition on the existence of import source directory --><available property="import.srcdir.available" file="${ext.dir}/${aid}" type="dir" /><fail unless="import.srcdir.available">the directory &quot;${ext.dir}/${aid}&quot; from which to import the assignment cannot be found</fail></target><!-- ensure all external properties required by target &quot;export&quot; are available and valid, and fail the build otherwise --><target name="-extvar-check-export" depends="-extvar-check-import-export"><!-- condition on the existence of export target directory --><available property="export.destdir.available" file="${ext.dir}" type="dir" /><fail unless="export.destdir.available">the directory &quot;${ext.dir}&quot; to which to export the assignment cannot be found</fail></target></project>

 定制的构建文件示例

对应于正文中的运行效果范例。

<project name="cloud-computing-assignment-mgmt" basedir="."><description>Simplify the assignment file management.The directory template for each assignment directory is such:root directory| report             [DIRECTORY]| project            [DIRECTORY]| pic                [DIRECTORY]| dist               [DIRECTORY]| ${dist.arc.name}   [FILE]wherereport        - directory for reportsproject       - directory for source codespic           - directory for snapshots, photos, etcdist          - temporary directory for holding submission files;appear only after target &quot;dist&quot;${dist.arc.name} - an archive file for submissionThe &quot;dist&quot; folder as well as the final archive contain thefollowing contents:* project directory unless it's empty* pic directory unless it's empty* the report file specified in external properties under the reportdirectoryExternal properties required:aid           - assignment_id, required by ALL targetsext.dir       - external directory, esp portable device, to temporarilyaccommodate the assignment directory, required bytarget &quot;import&quot; and &quot;export&quot;</description><property name="root_antfile" location="../../../build.xml" /><!-- 此处指定了压缩包名和报告名 --><property name="dist.arc.name" value="Lab${aid}.zip" /><property name="report.name" value="Lab${aid} Report.docx" /><!-- 如果在调用了根构建文件的相应任务后还有其它定制任务需要完成,直接加在<ant>调用之后即可 --><target name="make" description="make &quot;${aid}&quot; assignment directories"><ant antfile="${root_antfile}" target="make" /><!-- 这里写其它定制操作(虽然本例中不需要),下同 --></target><target name="dist" description="distribute the assignment under directory &quot;${aid}&quot; before removing the backup version of previous build if any"><ant antfile="${root_antfile}" target="dist" /></target><target name="clean-dist" description="clean distribution of assignment under directory &quot;${aid}&quot; but leave a backup version of original distributed archive intact"><ant antfile="${root_antfile}" target="clean-dist" /></target><target name="export" description="export assignment directory &quot;${aid}&quot; to directory specified by property &quot;ext.dir&quot;"><ant antfile="${root_antfile}" target="export" /></target><target name="import" description="import/update assignment directory &quot;${aid}&quot; from directory &quot;${ext.dir}/${aid}&quot; specified by property &quot;ext.dir&quot;"><ant antfile="${root_antfile}" target="import" /></target></project>

这篇关于适用于计算机学院同学的作业目录管理系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/925735

相关文章

Vite 打包目录结构自定义配置小结

《Vite打包目录结构自定义配置小结》在Vite工程开发中,默认打包后的dist目录资源常集中在asset目录下,不利于资源管理,本文基于Rollup配置原理,本文就来介绍一下通过Vite配置自定义... 目录一、实现原理二、具体配置步骤1. 基础配置文件2. 配置说明(1)js 资源分离(2)非 JS 资

Python如何实现高效的文件/目录比较

《Python如何实现高效的文件/目录比较》在系统维护、数据同步或版本控制场景中,我们经常需要比较两个目录的差异,本文将分享一下如何用Python实现高效的文件/目录比较,并灵活处理排除规则,希望对大... 目录案例一:基础目录比较与排除实现案例二:高性能大文件比较案例三:跨平台路径处理案例四:可视化差异报

99%的人都选错了! 路由器WiFi双频合一还是分开好的专业解析与适用场景探讨

《99%的人都选错了!路由器WiFi双频合一还是分开好的专业解析与适用场景探讨》关于双频路由器的“双频合一”与“分开使用”两种模式,用户往往存在诸多疑问,本文将从多个维度深入探讨这两种模式的优缺点,... 在如今“没有WiFi就等于与世隔绝”的时代,越来越多家庭、办公室都开始配置双频无线路由器。但你有没有注

创建springBoot模块没有目录结构的解决方案

《创建springBoot模块没有目录结构的解决方案》2023版IntelliJIDEA创建模块时可能出现目录结构识别错误,导致文件显示异常,解决方法为选择模块后点击确认,重新校准项目结构设置,确保源... 目录创建spChina编程ringBoot模块没有目录结构解决方案总结创建springBoot模块没有目录

基于Spring Boot 的小区人脸识别与出入记录管理系统功能

《基于SpringBoot的小区人脸识别与出入记录管理系统功能》文章介绍基于SpringBoot框架与百度AI人脸识别API的小区出入管理系统,实现自动识别、记录及查询功能,涵盖技术选型、数据模型... 目录系统功能概述技术栈选择核心依赖配置数据模型设计出入记录实体类出入记录查询表单出入记录 VO 类(用于

在Linux系统上连接GitHub的方法步骤(适用2025年)

《在Linux系统上连接GitHub的方法步骤(适用2025年)》在2025年,使用Linux系统连接GitHub的推荐方式是通过SSH(SecureShell)协议进行身份验证,这种方式不仅安全,还... 目录步骤一:检查并安装 Git步骤二:生成 SSH 密钥步骤三:将 SSH 公钥添加到 github

Linux系统中查询JDK安装目录的几种常用方法

《Linux系统中查询JDK安装目录的几种常用方法》:本文主要介绍Linux系统中查询JDK安装目录的几种常用方法,方法分别是通过update-alternatives、Java命令、环境变量及目... 目录方法 1:通过update-alternatives查询(推荐)方法 2:检查所有已安装的 JDK方

Linux下删除乱码文件和目录的实现方式

《Linux下删除乱码文件和目录的实现方式》:本文主要介绍Linux下删除乱码文件和目录的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux下删除乱码文件和目录方法1方法2总结Linux下删除乱码文件和目录方法1使用ls -i命令找到文件或目录

mysql中的数据目录用法及说明

《mysql中的数据目录用法及说明》:本文主要介绍mysql中的数据目录用法及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、版本3、数据目录4、总结1、背景安装mysql之后,在安装目录下会有一个data目录,我们创建的数据库、创建的表、插入的

如何使用Maven创建web目录结构

《如何使用Maven创建web目录结构》:本文主要介绍如何使用Maven创建web目录结构的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录创建web工程第一步第二步第三步第四步第五步第六步第七步总结创建web工程第一步js通过Maven骨架创pytho