I want this folder structure to be zipped as it is-
Right now I am doing these steps-
Moving files other than folders to "Temp" folder.
Moving Folder1 to "Temp" folder.
Zipping Temp.
Deleting "Temp folder".
Is this the correct approach or is there any simple/better way of doing this?
There is no need to move the files before zipping them.
<zip destfile="test.zip" basedir="src_dir" includes="**/*"/>
If you had a more challenging selection to make than **/*, e.g. include and exclude specific files selectively, then you could achieve that with one or more filesets (or zipfilesets) within the zip element.
Here is the dir structure, including build.xml:
$ find .
.
./build.xml
./src_dir
./src_dir/Document.txt
./src_dir/Document2.txt
./src_dir/Document3.xml
./src_dir/Folder1
Here is the zip file created:
$ jar tvf test.zip
0 Fri Jul 20 08:36:06 GMT 2012 Folder1/
0 Fri Jul 20 08:36:26 GMT 2012 Document.txt
0 Fri Jul 20 08:36:12 GMT 2012 Document2.txt
0 Fri Jul 20 08:36:18 GMT 2012 Document3.xml
Related
I need to write image parser from some website which will take images, some other info and save it to my local folder.
So let's say we have image at this url :
https://i.stack.imgur.com/MiqEv.jpg
(this is someone's SO avatar)
So I want to to save it to local folder. Let's say to "~/test/image.png"
I found this link
And I tried this in my terminal:
rails console
require 'open-uri'
open('~/test/image.jpg', 'wb') do
|file| file << open('https://i.stack.imgur.com/MiqEv.jpg').read
end
As you can see my home/test folder is empty
And I got this output from console
#<File:~/test/image.jpg (closed)>
What do I do?
Also I tried this:
require 'open-uri'
download = open('https://i.stack.imgur.com/MiqEv.jpg')
IO.copy_stream(download, '~/test/image.jpg')
And got this output:
=> #https://i.stack.imgur.com/MiqEv.jpg>, #meta={"date"=>"Fri, 06 May 2016
11:58:05 GMT", "content-type"=>"image/jpeg", "content-length"=>"4276",
"connection"=>"keep-alive",
"set-cookie"=>"__cfduid=d7f982c0742bf40e58d626659c65a88841462535885;
expires=Sat, 06-May-17 11:58:05 GMT; path=/; domain=.imgur.com;
HttpOnly", "cache-control"=>"public, max-age=315360000",
"etag"=>"\"b75caf18a116034fc3541978de7bac5b\"", "expires"=>"Mon, 04
May 2026 11:58:05 GMT", "last-modified"=>"Thu, 28 Mar 2013 15:05:35
GMT", "x-amz-version-id"=>"TP7cpPcf0jWeW2t1gUz66VXYlevddAYh",
"cf-cache-status"=>"HIT", "vary"=>"Accept-Encoding",
"server"=>"cloudflare-nginx", "cf-ray"=>"29ec4221fdbf267e-FRA"},
#metas={"date"=>["Fri, 06 May 2016 11:58:05 GMT"],
"content-type"=>["image/jpeg"], "content-length"=>["4276"],
"connection"=>["keep-alive"],
"set-cookie"=>["__cfduid=d7f982c0742bf40e58d626659c65a88841462535885;
expires=Sat, 06-May-17 11:58:05 GMT; path=/; domain=.imgur.com;
HttpOnly"], "cache-control"=>["public, max-age=315360000"],
"etag"=>["\"b75caf18a116034fc3541978de7bac5b\""], "expires"=>["Mon, 04
May 2026 11:58:05 GMT"], "last-modified"=>["Thu, 28 Mar 2013 15:05:35
GMT"], "x-amz-version-id"=>["TP7cpPcf0jWeW2t1gUz66VXYlevddAYh"],
"cf-cache-status"=>["HIT"], "vary"=>["Accept-Encoding"],
"server"=>["cloudflare-nginx"], "cf-ray"=>["29ec4221fdbf267e-FRA"]},
#status=["200", "OK"]>
2.3.0 :244 > IO.copy_stream(download, '~/test/image.jpg') => 4276
But my folder is still empty.
What do I do??
The problem is that the file is not getting created. If you create the file using File.open or open and then execute the `IO.copy_stream' it will work.
Also ~/ doesn't work in ruby. You have to specify the whole path.
require 'open-uri'
download = open('https://i.stack.imgur.com/MiqEv.jpg')
open('/home/user/image.jpg', 'w')
IO.copy_stream(download, '~/test/image.jpg')
If you want a directory to be created as well, you will have to user Dir.mkdir. If you want to create nested directories use FileUtils::mkdir_p. If it is difficult to use either, I would suggest using system 'mkdir dirname' or system 'mkdir -p dir1/dir2/dir3'
Dir.mkdir '/home/user/test' # doesnt work for nested folder creation
require 'fileutils'
FileUtils::mkdir_p '/home/user/test1/test2' # for nested
system 'mkdir '~/test' # Unix command for directory creation
system 'mkdir -p '~/test1/test2' # Unix command for nested directory
Hope this helps
If you are using Ubuntu, could you just use the wget?
You can use both wget 'https://i.stack.imgur.com/MiqEv.jpg' and system("wget 'https://i.stack.imgur.com/MiqEv.jpg'"). Or system("wget 'https://i.stack.imgur.com/MiqEv.jpg' > /your/path
Note: for the first command you need to wrap you command into the ` signs. This will cause ruby to call a system command.
Also, consider using /home/your_name instead of just ~. Also notice the leading / slash.
I used the below task to compress the folder to a zip file. But I found that the symbolic links in the folder lost when I unzipped the zip file.
<zip destfile="${file.path}">
<fileset dir="/tmp"/>
</zip>
For instance, previously, the file look like below.
lrwxrwxrwx 1 xxxx xxxx 25 Mar 15 21:02 libboost_atomic.so -> libboost_atomic.so.1.57.0
-rwxr-xr-x 1 xxxx xxxx 9135 Feb 8 04:46 libboost_atomic.so.1.57.0
After I compressed the folder using Ant and unzipped it, it look like below.
-rw-r--r-- 1 xxxx xxxx 9135 Feb 8 04:46 libboost_atomic.so
-rw-r--r-- 1 xxxx xxxx 9135 Feb 8 04:46 libboost_atomic.so.1.57.0
instead of the built-in zip command, try the using the exec and use
<exec executable="zip">
<arg value="--symlinks"/>
<arg value="-r"/>
<arg value="${file.path}"/>
<arg value="tmp"/>
</exec>
I tried the command line equivalent on mac and worked for me, please let me know on what system are you trying this.
Note, this requires you to have a 'zip' executable in your path (which I assume you do)
The zip format itself doesn't really support symbolic links in a portable way (and Ant doesn't support any of the not-so-portable options). Neither does Ant's tar task.
I use the Docker 1.8.3. The /var/lib/docker/repositories-aufs stores the local images information matching the output of # docker images. The /var/lib/docker/graph/<image GUID> maintain metadata and so on for each images.
The json holds metadata about the image.
The layersize indicates the size of the layer.
And what is the tar-data.json.gz and v1Compatibility?
# ll /var/lib/docker/graph/ca0ef69
drwx------ 2 root root 4096 10月 29 12:08 ./
drwx------ 150 root root 20480 11月 1 12:29 ../
-rw------- 1 root root 1384 10月 29 12:06 json
-rw------- 1 root root 1 10月 29 12:06 layersize
-rw------- 1 root root 82 10月 29 12:06 tar-data.json.gz
-rw------- 1 root root 1384 10月 29 12:08 v1Compatibility
tar-data.json.gz stores the image layer:
This seems to have been introduced in docker 1.8 by PR 14067.
This pull request introduces a library (vbatts/tar-split) that is for inline disassembly of TAR archives.
The disassembly does not do any extraction, but preserves the raw bytes of headers and padding from the archive, and defers the extraction. This way validation and extraction continue to be a lockstep process.
For an docker pull, docker load or docker commit after this feature, there will be a new state file stored for the image layer (e.g. /var/lib/docker/graph/<ID>/tar-data.json.gz).
For existing images that do not have this new state file, the tar archive produced by docker save or docker push will fallback to the traditional graphdriver.Diff as they have been.
The benefit of this feature is that rather than hoping the graph.TarLayer produced is deterministic, the tar archive will be reassembled from the raw bytes of the original archive.
Presently the issue exists that an image pulled from a repo like the Docker hub, and then pushed to a local registry may likely have a new digests.
v1compatibility was introduced in docker 1.3 (commit 15d5c7f), but is used only with docker 1.8 (commit 745820f) in manifest.go
// History stores unstructured v1 compatibility information
type History struct {
// V1Compatibility is the raw v1 compatibility information
V1Compatibility string `json:"v1Compatibility"`
}
And really used in docker 1.9 (commit 504e67b) in graph/graph.go, where the v1Compatibility JSON data associated
with the image in the manifest is stored to the disk.
Then graph/pull_v2.go, when attempting a tag reuse, can check for its compatibility.
You can see it used in graph/pull_v2_test.go.
I have the following in ./bash_profile
export SRCROOT=/users/benjamin.beasley/work/svn/ccdev
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk_dev/Contents/Home
export PATH=$PATH$:~/tools/tools-versions/gradle-2.2.1/bin
export PATH=$PATH$:~/tools/activator
In ~/tools/tools-versions/gradle-1.12/bin, I do
drwxr-xr-x# 4 xxx.xxx WORKDAYINTERNAL\Domain Users 136 Nov 12 11:47 .
drwxr-xr-x# 13 xxx.xxx WORKDAYINTERNAL\Domain Users 442 Apr 29 2014 ..
-rwxr-xr-x# 1 xxx.xxx WORKDAYINTERNAL\Domain Users 5071 Apr 29 2014 gradle
-rwxr-xr-x# 1 xxx.xxx WORKDAYINTERNAL\Domain Users 2395 Apr 29 2014 gradle.bat
echo $PATH$:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin$:/Users/xxx.xxx/tools/tools-versions/gradle-2.2.1/bin$:/Users/xxx.xxx/tools/activator90566
so I get the gradle executable which is executable. I can execute it from this directory. But if I start a new shell, and type "gradle" it says command not found. But I "echo $PATH$" and I see that the full canonical path to the ~/tools/tools-versions/gradle-2.2.1/bin folder is there.
However I can execute activator which is an executable in the ~/tools/activator directory. I have no clue why bash knows about activator and not gradle.
In summary:
gradle is executable by this user
gradle can be run from the command line.
gradle is in the $PATH$ environment variable
other programs such as activator, which are also in $Path$ are executable anywhere in terminal regardless of directory which is what I want to be true of gradle.
Unix environment variables are $PATH not $PATH$ (they aren't like Windows env vars).
This is causing your problem.
This path is busted: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin$:/Users/xxx.xxx/tools/tools-versions/gradle-2.2.1/bin$:/Users/xxx.xxx/tools/activator90566
Notice the 90566 at the end? That's from $$ having been expanded to the current process id when you set the variable.
None of these are paths that actually exist or work:
/opt/X11/bin$
/Users/xxx.xxx/tools/tools-versions/gradle-2.2.1/bin$
/Users/xxx.xxx/tools/activator90566
I want to use the Neo4j shell. With the V1.9 release, it was in the bin folder of the installation, but since I upgraded to v2.0.0-M06, I can no longer find it. The bin folder only contains the following files ...
Directory of C:\Program Files\Neo4j Community\bin
16/10/2013 15:38 <DIR> .
16/10/2013 15:38 <DIR> ..
16/10/2013 15:38 37 neo4j-community-user-vmoptions.loc
14/10/2013 09:38 491,016 neo4j-community.exe
16/10/2013 15:38 242 neo4j-community.vmoptions
14/10/2013 09:37 39,564,808 neo4j-desktop-2.0.0-M06.jar
4 File(s) 40,056,103 bytes
2 Dir(s) 16,272,773,120 bytes free
I know I can use the shell in the web UI, but I want to pipe input and output, and I can't figure how to do that except with the stand-alone shell. Any ideas?
I have found the answer - in another question - How to install Neo4j 2.0+ as a windows service .
By downloading the zip file rather than the windows installer, I get all the .bat files, including Neo4jshell.bat. Problem solved!
Try this:
cd C:\Program Files\Neo4j Community
jre\bin\java -cp bin\neo4j-desktop-1.9.4.jar org.neo4j.shell.StartClient [--file /your/file/of/stuff.cyp]