Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 29.548.891 Times


Company: Filip Noetzel
Date Added: September 27, 2013  |  Visits: 247


Report Broken Link
Printer Friendly Version

Product Homepage
Download (17 downloads)

Copies files to filenames based on their contents<br /><br />hashedassets is a command-line tool that copies files to filenames based on their contents. It also writes a map of what was renamed to what, so you can find your files.<br /><br />Main purpose of this is that you can add a far future Expires header to your components. Using hash based filenames is a lot better than using your $VCS revision number, because users only need to download files that didn't change.<br /><br />Creating some source files<br /><br />First, we create a file to be hashed:<br /><br />>>> system("mkdir input/")<br />>>> system("mkdir input/subdir/")<br />>>> system("mkdir maps/")<br />>>> with open("input/foo.txt", "w") as file:<br />... file.write("foo")<br /><br />>>> with open("input/subdir/bar.txt", "w") as file:<br />... file.write("bar")<br /><br />>>> system('touch -t200504072213.12 input/foo.txt')<br /><br />Simple usage<br /><br />>>> system("hashedassets maps/map.txt input/*.txt input/*/*.txt output/")<br />mkdir 'output'<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> print open("maps/map.txt").read()<br />subdir/bar.txt: Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt<br />foo.txt: C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt<br />< BLANKLINE ><br /><br />>>> system("ls output/")<br />C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt<br />Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt<br /><br />>>> system("ls maps/")<br />map.txt<br /><br />Logging level<br /><br />If we tell the command to be quiet, it does not print what it is doing:<br /><br />>>> system("hashedassets -q maps/map2.txt input/*.txt input/*/*.txt output/")<br /><br />If we tell the command to be more verbose, it logs more information:<br /><br />>>> system("hashedassets -vvv maps/map3.txt input/*.txt input/*/*.txt output/")<br />Debug level set to 10<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />Modification time is also preserved:<br /><br />>>> old_stat = os.stat("input/foo.txt")<br />>>> new_stat = os.stat("output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt")<br />>>> [(getattr(old_stat, prop) == getattr(new_stat, prop))<br />... for prop in ('st_mtime', 'st_atime', 'st_ino',)]<br />[True, True, False]<br /><br />We can easily do this with multiple formats:<br /><br />javascript<br /><br />>>> system("hashedassets -n my_callback maps/map.js input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> print open("maps/map.js").read()<br />var my_callback = {<br /> "foo.txt": "C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt",<br /> "subdir/bar.txt": "Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt"<br />};<br /><br />JSON<br /><br />>>> system("hashedassets -n my_callback maps/map.json input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> print open("maps/map.json").read()<br />{<br /> "foo.txt": "C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt",<br /> "subdir/bar.txt": "Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt"<br />}<br /><br />JSONP<br /><br />>>> system("hashedassets -n my_callback maps/map.jsonp input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> print open("maps/map.jsonp").read()<br />my_callback({<br /> "foo.txt": "C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt",<br /> "subdir/bar.txt": "Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt"<br />});<br /><br />Sass<br /><br />Sass is a meta language on top of CSS.<br /><br />>>> system("hashedassets -n my_callback maps/map.scss input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> print open("maps/map.scss").read()<br />@mixin my_callback($directive, $path) {<br /> @if $path == "subdir/bar.txt" { #{$directive}: url("Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt"); }<br /> @else if $path == "foo.txt" { #{$directive}: url("C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt"); }<br /> @else {<br /> @warn "Did not find "#{$path}" in list of assets";<br /> #{$directive}: url($path);<br /> }<br />}<br /><br />PHP<br /><br />>>> system("hashedassets -n my_callback maps/map.php input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> print open("maps/map.php").read()<br />$my_callback = array(<br /> "subdir/bar.txt" = > "Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt",<br /> "foo.txt" => "C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt",<br />)<br /><br />Sed<br /><br />We can also generate a sed script that does the replacements for us:<br /><br />>>> system("hashedassets -n my_callback maps/map.sed input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> print open("maps/map.sed").read()<br />s/subdir/bar.txt/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt/g<br />s/foo.txt/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt/g<br />< BLANKLINE ><br /><br />We should also be able to use this directly with sed<br /><br />>>> with open("replaceme.html", "w") as file:<br />... file.write('< a href=foo.txt >bar< /a >')<br /><br />The script is then applied like this:<br /><br />>>> system("sed -f maps/map.sed replaceme.html")<br />< a href=C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt >bar< /a ><br /><br />However, '.' is not treated as wildcard, so the following does not work<br /><br />>>> with open("replaceme2.html", "w") as file:<br />... file.write('< a href=fooAtxt >bar< /a >')<br /><br />>>> system("sed -f maps/map.sed replaceme2.html")<br />< a href=fooAtxt >bar< /a ><br /><br />Specifying the type with -t<br /><br />The type of the map is guessed from the filename, but you can specify it as well:<br /><br />>>> system("hashedassets -t js cantguessmaptype input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />Specifying the length of the filename with -l<br /><br />>>> system("hashedassets -l 10 maps/shortmap.json input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/C-7Hteo_D9.txt'<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IO.txt'<br /><br />>>> system("rm output/C-7Hteo_D9.txt output/Ys23Ag_5IO.txt")<br /><br />Specifying the digest with -d<br /><br />>>> system("hashedassets -d md5 maps/shortmap.json input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/rL0Y20zC-Fzt72VPzMSk2A.txt'<br />cp 'input/subdir/bar.txt' 'output/N7UdGUp1E-RbVvZSTy1R8g.txt'<br /><br />>>> system("rm output/rL0Y20zC-Fzt72VPzMSk2A.txt output/N7UdGUp1E-RbVvZSTy1R8g.txt")<br /><br />Re-using a map<br /><br />The program reads in maps it created in a prior run to only copy files that haven't changed since. So, the following commands do not copy any files:<br /><br />>>> system("hashedassets maps/map.scss input/*.txt input/*/*.txt output/")<br />>>> system("hashedassets maps/map.php input/*.txt input/*/*.txt output/")<br />>>> system("hashedassets maps/map.js input/*.txt input/*/*.txt output/")<br />>>> system("hashedassets maps/map.json input/*.txt input/*/*.txt output/")<br />>>> system("hashedassets maps/map.sed input/*.txt input/*/*.txt output/")<br />>>> system("hashedassets maps/map.jsonp input/*.txt input/*/*.txt output/")<br />>>> system("hashedassets maps/map.txt input/*.txt input/*/*.txt output/")<br /><br />If we touch one of the input files in between, the file will be read but not copied because the hashsum is the same:<br /><br />>>> system('touch -t200504072214.12 input/foo.txt')<br />>>> system("hashedassets maps/map.json input/*.txt input/*/*.txt output/")<br /><br />If we change the file's content, it will get a new name:<br /><br />>>> with open("input/foo.txt", "w") as file:<br />... file.write("foofoo")<br /><br />>>> system("hashedassets maps/map.json input/*.txt input/*/*.txt output/")<br />rm 'output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'<br />cp 'input/foo.txt' 'output/QIDaFD7KLKQh0l5O6b8exdew3b0.txt'<br /><br />If you then list the files in the directory, note that the old file ''output/C-7Hteo_D9vJXQ3UfzxbwnXaijM.txt'' is gone:<br /><br />>>> system("ls output/")<br />QIDaFD7KLKQh0l5O6b8exdew3b0.txt<br />Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt<br /><br />If we remove one of the created files, it gets recreated:<br /><br />>>> system("rm output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt")<br />>>> system("hashedassets maps/map.json input/*.txt input/*/*.txt output/")<br />cp 'input/subdir/bar.txt' 'output/Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt'<br /><br />>>> system("ls output/")<br />QIDaFD7KLKQh0l5O6b8exdew3b0.txt<br />Ys23Ag_5IOWqZCw9QGaVDdHwH00.txt<br /><br />If a file that is about to be removed because the original content changed, it isn't recreated:<br /><br />>>> system("rm output/QIDaFD7KLKQh0l5O6b8exdew3b0.txt")<br />>>> with open("input/foo.txt", "w") as file:<br />... file.write("foofoofoo")<br />>>> system("hashedassets maps/map.json input/*.txt input/*/*.txt output/")<br />cp 'input/foo.txt' 'output/NdbmnXyjdY2paFzlDw9aJzCKH9w.txt'<br /><br />Error handling<br /><br />However, if we run this with no arguments, it fails:<br /><br />>>> system("hashedassets", external=True)<br />Usage: hashedassets [ options ] MAPFILE SOURCE [...] DEST<br />< BLANKLINE ><br />hashedassets: error: You need to specify at least MAPFILE SOURCE and DEST

Requirements: No special requirements
Platforms: *nix, Linux
Keyword: Callback Files Inputfootxt Inputsubdirbartxt Inputtxt Mapsmapjson Outputc Hteo Vjxq Ufzxbwnxaijmtxt Outputquotcp Outputquotgtgtgt Outputys Iowqzcw Qgavddhwh Txt Gtgtgt Print Quotwquot Systemquothashedassets
Users rating: 0/10

License: Freeware Size: 20.48 KB
More Reviews or Write Review

Libraries  -  XML::Writer::Simple 0.01
XML::Writer::Simple is a Perl module to create XML files easily! SYNOPSIS use XML::Writer::Simple dtd => "file.dtd"; print para("foo",b("bar"),"zbr"); USAGE This module takes some ideas from CGI to make easier the life for those who need...
4.1 KB  
Libraries  -  MP3::Album 0.14
MP3::Album is a Perl extension to manage a music album built of mp3 files. SYNOPSIS use MP3::Album; $mp3_album = MP3::Album->new(files=>@files); #check is as set of mp3 has a uniform encoding if ($mp3_album->bitrate_check()) &&...
8.19 KB  
Libraries  -  AnyData::Format::Mp3 0.10
AnyData::Format::Mp3 is a tied hash and DBI access to Mp3 files. SYNOPSIS use AnyData; my $playlist = adTie( Passwd, [c:/My Music/] ); while (my $song = each %$playlist){ print $song->{artist} if $song->{genre} eq Reggae } OR use DBI...
44.03 KB  
File Utilities  -  dupfinder for Linux 1.4.3
dupfind is a Python utility that allows you to find duplicated files and directories in your file system. Show how utility find duplicated files: By default utility identifies duplication files by file content.
10.24 KB  
File Cataloguers  - Folder-To-TXT 1.01
Do you know this situation? You just burned a disk, you collected some data on a USB stick or you simply organized some files on your local hard drive. Now you want to get an editable list of all files in this directory including sub-foldersĀ¦ but...
111.95 KB  
Libraries  -  Text::MetaText 0.22
Text::MetaText is a Perl extension implementing meta-language for processing "template" text files. SYNOPSIS use Text::MetaText; my $mt = Text::MetaText->new(); # process file content or text string print $mt->process_file($filename,...
87.04 KB  
Network & Internet  -  Download Sentinel++ 2.1.0
Download Sentinel++ is an Anti-leech, download limiter / file manager, that uses tokens to verify downloads instead of HTTP_REFERER or IP which can be spoofed or changed. The install is as painless as possible with only one file to upload and...
143.36 KB  
File Cataloguers  -  FileTagSleuth 1.0
FileTagSleuth is the totally FREE, easy and quick MP3 tag and photo EXIF viewer. Search through your MP3 tags, read photo information, and export all of your files tags instantly for later viewing. Just drag and drop to start, then search,...
3.19 MB  
Clipboard Utilities  -  Day Clipboard Utility 2. 4. 2005
Day Clipboard Utility automatically captures every text or image copied (CTRL+C) and saves them in TXT and BMP files. It can be minimized and automatically captures every text or image copied (CTRL+C) and saves them in TXT (the text) and BMP (the...
188 KB  
Business  -  PCLReader for Mobile PCL 8.895
PCLReader views, converts and prints PDA- and Mobile device-generated HP PCL print files with extensions like SPP, PCL or PRN. This is useful when you are viewing long documents that you want to view later and a mobile or wireless printer is not...
8.1 MB  
Shell & Desktop  -  Glunarclock 0.32.4
GNOME Lunar Clock Applet displays the current phase of the Moon as an applet for the gnome panel. In the properties box you can choose between a real image Features Pointing with the mouse at the applet...
522.24 KB  
Shell & Desktop  -  KOpenBabel 0.2
KOpenBabel is a graphical interface to Open Babel.[1] KOpenBabel can handle and convert over 70 chemical file formats. At this time, it can convert files, guess input file type and convert a large number of files with a single click. The user...
20.48 KB  
Shell & Desktop  -  Fekete 5
Icon theme for Linux For all possible desktop, and Linux distro Special additives: Suse's Yast icons. Xfce system icons, and archaic mimetypes icons Mandriva "special placed" status icons. Libreoffice icons.
71.59 MB  
Shell & Desktop  -  DesktopTools 02-alpha
DesktopTools is a collection of small utillities which help to make your daily life easier. Since the tools themself are rather small (projectwise) I keep them not as individual projects, but have them under this collective name.
102.4 KB  
Shell & Desktop  -  XFast 0.9
XFast is a slim and lightweighted desktop environment that incorporates X and Window Manager within the same project.
1.15 MB  
File Utilities  -  Active@ KillDisk Linux Console 9.1.1110
Active@ KillDisk for Linux (Console) is a powerful utility that will: wipe confidential data from unused space on your hard drive; erase data from partitions or from an entire hard disk; destroy data permanently. Active@ KillDisk for Linux...
11.07 MB  
File Utilities  -  Metalinks 5.1
Metalinks is a project to facilitate data distribution over mirrors and P2P networks. It does so by defining an XML format and the tools to handle these. The metalink files contain all the information needed to download and verify files.
5.05 MB  
File Utilities  -  SSH LoginWatcher 0.9
LoginWatcher is tailing your messages file and is waiting for an entry representing a failed login attempt via SSH. After a predefined number of attempts, the IP address of the offending host is added to the hosts.deny file to prevent further logins.
10.24 KB  
File Utilities  -  PUFS 0.0.2c
PUFS - Peer Union File System - is a poor man's na???ve distributed file system built on top of FUSE, hence running totally in user space. The project is distributed under the GPL license. PUFS' philosophy is somewhat in line...
408.58 KB  
File Utilities  -  frfs 0.0.3
frfs implements a fully functional in-RAM filesystem using the FUSE framework. Overview: With Linux, creating RAM-backed file system is easy: su to root, mount a tmpfs some place, come back to plain user. Ah, but...
153.6 KB