cli将文件归档到与时间相关的容器(目录或归档)中。

dalimil的Python项目详细描述


达利米

将文件存档到与时间相关的容器(目录或存档)。

有一个文件目录。在这种情况下,它们将日期时间编码为文件名:

$ ls
2017-09-27T00_27_05Z8H47_U.xml
2017-09-27T00_43_00ZLJQASR.xml
2017-09-27T00_46_41ZPMZOpb.xml
2017-09-27T00_50_07Z7KiJAe.xml
2017-09-27T00_50_17ZXj7pCs.xml
2017-09-27T01_03_09Z_LuWzf.xml
2017-09-27T01_07_27ZE_Mo1_.xml
2017-09-27T01_12_22Zw1A_di.xml
2017-09-27T01_15_32ZsH7mLr.xml
2017-09-27T01_31_26ZJnFw8F.xml
...

让dalimil存档文件:

$ dalimil -a move2zip *.xml
...
...
...
2017-10-02 09:53:02.412068 - Dalimil completed his Chronicle.

默认时间段为一天,而move2zip将一个时间段存档到一个zip文件中 进入每年和每月分组的目录树:

$ tree archive
archive
├── year-2016
│   ├── month-08
│   │   ├── 2016-08-24.zip
│   │   ├── .....
│   │   └── 2016-08-31.zip
│   ├── month-09 ...
│   ├── month-10 ...
│   ├── month-11 ...
│   └── month-12 ...
└── year-2017
    ├── month-01 ...
    ├── month-02 ...
    ├── month-03 ...
    ├── month-04 ...
    ├── month-05 ...
    ├── month-06 ...
    ├── month-07 ...
    ├── month-08 ...
    ├── month-09
    │   └── .....
    └── month-10
        └── 2017-10-01.zip

move2zipaction已将过去的所有时段(在本例中是一天)打包到每日 压缩存档文件,将其放入存档树中,并从源中删除原始文件 目录。

当前期间(默认为今天)的文件在源目录中保持不变。

先决条件

python 2.6、2.7、3.3、3.4、3.5或3.6

在Windows和Linux上运行。

警告

文件可以删除-使用它的风险自己承担!!!

有些操作正在删除文件(在文件被处理之后),因此请注意。

这个工具是精心设计的,经常使用几年 没有问题,所以它会工作得很好。

但它是人类创造的软件。

安装

使用pip:

$ pip install dalimil

此后,应可使用命令dalimil

用法

$ dalimil -h

usage: dalimil [-h]
               [-action {list,move2dir,move2zip,move2targz,copy2dir,copy2zip,copy2targz}]
               [-destination DESTINATION] [-time {modified,pattern}]
               [-pattern TIME_DETECTION_PATTERN] [-incomplete]
               source [source ...]

dalimil tool organizes files into time related containers (directories or archives).
Note: This command never starts anything by itself, it runs only once per call.

So called Dalimil wrote Chronicle of Dalimil, sorting past and current events.
See http://en.wikipedia.org/wiki/Chronicle_of_Dalimil

positional arguments:
  source                Unix shell pattern for selecting files to archive.
                        (defaults to all files in current dir)

optional arguments:
  -h, --help            show this help message and exit
  -action {list,move2dir,move2zip,move2targz,copy2dir,copy2zip,copy2targz}
                        Defines action to do with files organized into time
                        related containers. (default: list)
  -destination DESTINATION
                        Time formated pattern for resulting container
                        (default: archive/year-%Y/month-%m/%Y-%m-%d.zip)
  -time {modified,pattern}
                        Method, how time of file is detected, options:
                        modified, pattern (default: modified)
  -pattern TIME_DETECTION_PATTERN
                        Pattern, detecting time from filename. Effective only,
                        if -time_detection_method is "pattern". Path is
                        ignored, first part of filename must fit, useless end
                        of filename can be omitted. (default:
                        %Y-%m-%dT%H_%M_%S))
  -incomplete           Allows creation of containers for periods, which are
                        not yet completed (default: False))

Files are selected using Unix shell like syntax using *, ?, [seq] and [!seq]
Finally, files are placed container, which is archive file or end leaf directory.
Warning: File selection pattern can select files from multiple directories.
If final container rejects storing duplicate names, duplicates are skipped.

Time is detected from file modification or creation time, or decoded from filename.

Resulting containers are defined by time formating pattern.

Time formating patters for target path and container name:
Defines path and file name, which can be created from related file time.
    %c Locale's appropriate date and time representation.
    %d Day of the month as a decimal number [01,31].
    %f Microsecond as a decimal number [0,999999], zero-padded on the left
    %H Hour (24-hour clock) as a decimal number [00,23].
    %j Day of the year as a decimal number [001,366].
    %m Month as a decimal number [01,12].
    %M Minute as a decimal number [00,59].
    %S Second as a decimal number [00,61].
    %U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.
    %w Weekday as a decimal number [0(Sunday),6].
    %W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.
    %y Year without century as a decimal number [00,99].
    %Y Year with century as a decimal number.
    %z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).
    %Z Time zone name (empty string if the object is naive).
For more and details see bottom of page http://docs.python.org/library/datetime.html
Samples: pattern => resulting path + archive name:
    "archive/%Y-%m-%dT%H.zip" => "archive/2010-02-28T13.zip"
    "archive/%Y/%m/%d.zip" => "archive/2010/02/28.zip"
    "archive/%Y/week-%W.zip" => "archive/2010/week-10.zip"
default value is:
    "archive/year-%Y/month-%m/%Y-%m-%d.zip" => "archive/year-2010/month-08/2010-08-28.zip"

Containers contain flat structure without deeper directory tree.
Source files can be finally deleted or left as they are.
Use action list (default) to see expected result without endangering files.

Existing containers are never touched, if they are found, *_1.* etc. is used.

Reading command line parameters from file: write arguments into text file,
each prefix and each value on separate lines like
    ------(quotation of my.cfg start)
    -action
    movetozip
    D:\my files with spaces\data\2010-0[789]\*.xml
    E:/other/location/data\2010-0[789]\*.xml
    (quotation of my.cfg end)------
Then from command line
    dalimil -incomplete @my.cfg
will read it.
Mixing command line arguments and others from file(s) is possible.

Examples:
Dry test of archiving *.xml from current folder without touching the files
    dalimil *.xml

Move the *.xml fles into subdir archive/year-2010/month-08/2010-08-28.zip etc.
Current period are skipped
    dalimil -a move2zip *.xml

Move there all files, including current period
    dalimil -a move2zip -incomplete *.xml

Copy the *.xml files into dir structure without zipping (dirs keep the .zip extension)
    dalimil -a copy2dir *.xml

Move the *.xml files into dir structure of style archive/year-2010/month-08/2010-08-28
    dalimil -a move2dir -d archive/year-%Y/month-%m/%Y-%m-%d *.xml

Move to archives, detecting time of files from file names
Expecting file names notes-201010251325_abc.xml
    dalimil -t pattern -p notes-%Y%m%d%H%M -a move2zip *.xml

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
屏幕抓取如何使用java从网站中提取数据?   java如何通过查看gc日志来查看垃圾收集器正在运行?   java中的并发   java计时一件事需要多长时间(秒)   java Hibernate:将mysql查询Datedif转换为HQL查询   AndroidStudio/Flatter中循环数的java怪异   java印地语字体在使用javafx的webview浏览器上呈现不正确   解码将bytebuffer转换为在java中不起作用的字符串   读一本书。用Java将dat文件转换为数组   java大小带有嵌入式SwingNode的JavaFX对话框   java你推荐Apache Maven的哪个软件安装程序插件?   实例变量错误:Java中需要标识符   无锁算法中的javaaba   java Quarkus native获取注释的值   java如何将用户输入功能添加到eclipse插件中?   java阻止在selenium webdriver测试中加载外部内容   未在本地缓存java映像(使用通用映像加载程序)会降低映像加载时间   Groovy:java。lang.VerifyError:希望在堆栈上找到整数   java cxf wssecurity客户端不绑定配置文件   java应用程序崩溃的测试工具/方法