I would like to present the output of a tree command in a Restructured Text document. I am using this code:
.. code-block:: bash
project
├── demo.py
├── LICENCE.txt
├── processes
│ ├── area.py
│ └── bboxinout.py
├── pywps.cfg
├── requirements.txt
├── server.py
├── setup.py
├── static
├── templates
└── tests
Which is producing the following output:
I then tried to replace the tree characters with unicode definitions, such as:
.. |hbar| unicode:: 01C0 ..
But the |hbar| sequence is printed verbatim when used inside a code block.
Is there any other way to force these characters to be printed correctly?
In ReST, I use literal blocks to represent tree structures:
::
project
├── demo.py
├── LICENCE.txt
├── processes
│ ├── area.py
│ └── bboxinout.py
├── pywps.cfg
├── requirements.txt
├── server.py
├── setup.py
├── static
├── templates
└── tests
I hope this helps!
A bit too late to answer your question now, but for anyone coming across this question, I managed to display a tree by using line blocks, i.e. adding "| " at the start of every line, as such:
| project
| ├── demo.py
| ├── LICENCE.txt
| ├── processes
| │ ├── area.py
| │ └── bboxinout.py
| ├── pywps.cfg
| ├── requirements.txt
| ├── server.py
| ├── setup.py
| ├── static
| ├── templates
| └── tests
And when you make your html, this should give you something like this:
It's not perfect and it does not wrap the tree in a block, but does show the tree.
Hope this helps.
Related
Following the documentation, the default file structure is:
.
└── public
└── locales
├── en
| └── common.json
└── de
└── common.json
When we can add different .json files under each language.
In my NextJS application I structured many different services and I want to have different translations for each.
I would like to create a locales folder for each specific service, which will be in the service itself. Or at least have a sub-folder under locales or under each language with the name of the service.
Something like this:
.
└── public
└── locales
├── en
| ├── service_one
| | └── content.json
| └── service_two
| └── content.json
└── de
├── service_one
| └── content.json
└── service_two
└── content.json
Or even better, something like
|
└── service_one
└── locales
├── en
| └── content.json
└── de
└── content.json
I can't find a way to target sub-folders, or different localePath for different pages.
So I'm building a WP plugin and it's customary to put empty index.html files into every folder to prevent directory listing where the host allows it. I'm building the deployment-ready package with grunt, but the only thing I'm missing are these files. I have many folders and would rather not create these files by hand. I'm happy to create one, and make Grunt copy that file to every path. But how?
No additional grunt plug-ins are necessary. Your requirement can be achieved using Grunt's built-in features.
Consider adding a custom Task to your Gruntfile.js as per the one named createEmptyHtmlFiles shown below.
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
// ...
});
/**
* Custom task to create empty `index.html` file in all folders.
*/
grunt.registerTask('createEmptyHtmlFiles', function() {
var fileName = 'index.html',
contents = '';
grunt.file.expand({ filter: 'isDirectory' }, 'dist/**/*')
.forEach(function(dirPath) {
var htmlFilePath = dirPath + '/' + fileName;
grunt.file.write(htmlFilePath, contents, { encoding: 'utf8'})
});
});
grunt.registerTask('default', ['createEmptyHtmlFiles']);
};
Explanation:
Typically your Gruntfile.js will include grunt.initConfig({ ... }); section that defines the configuration of various Tasks that you want to perform. This part should remain as per your current configuration.
A custom Task named createEmptyHtmlFiles is registered that does the following:
Assigns the desired filename, i.e. index.html, to the fileName variable and also assigns an empty string to the contents variable.
Next we utilize grunt.file.expand to which we pass a globbing pattern. In the example above the glob provided is 'dist/**/*'. The globbing pattern combined with the filter: 'isDirectory' option essentially obtains the pathnames to all folders inside the dist directory.
Important: This glob pattern you will need to change as per your directory structure.
Next we iterate each directory pathname using the Array's forEach method.
In each turn of the forEach loop we assign to the htmlFilePath variable a new pathname for where the resultant index.html file is to be created.
Each index.html file is created using grunt.file.write.
Demo:
Lets say the project directory is structured as follows:
.
├── Gruntfile.js
├── dist
│ ├── a
│ │ ├── b
│ │ │ └── 1.txt
│ │ └── c
│ │ └── 2.txt
│ ├── d
│ │ ├── 3.txt
│ │ └── e
│ │ └── 4.txt
│ └── f
│ └── g
│ └── 5.txt
├── node_modules
│ └── ...
└── package.json
Given the Gruntfile.js above after running $ grunt it will change to the following:
.
├── Gruntfile.js
├── dist
│ ├── a
│ │ ├── b
│ │ │ ├── 1.txt
│ │ │ └── index.html <-----
│ │ ├── c
│ │ │ ├── 2.txt
│ │ │ └── index.html <-----
│ │ └── index.html <-----
│ ├── d
│ │ ├── 3.txt
│ │ ├── e
│ │ │ ├── 4.txt
│ │ │ └── index.html <-----
│ │ └── index.html <-----
│ └── f
│ ├── g
│ │ ├── 5.txt
│ │ └── index.html <-----
│ └── index.html <-----
├── node_modules
│ └── ...
└── package.json
Note Every folder inside the dist directory now includes an empty index.html file.
You may need to exclude the index.html from being created in specific directories. In which case we can you can negate specific directories via the glob pattern(s) passed to the grunt.file.expand method.
For instance, lets say we configure it as follows in the createEmptyHtmlFiles task:
...
grunt.file.expand({ filter: 'isDirectory' }, ['dist/**/*', '!dist/a/{b,c}'])
...
Note: This time we pass an Array that contains two glob patterns. The first one is the same as per the previous example, however the second one begins with ! which will negate a match.
Running $ grunt using the the aforementioned glob patterns will result in the following directory structure:
.
├── Gruntfile.js
├── dist
│ ├── a
│ │ ├── b
│ │ │ └── 1.txt
│ │ ├── c
│ │ │ └── 2.txt
│ │ └── index.html <-----
│ ├── d
│ │ ├── 3.txt
│ │ ├── e
│ │ │ ├── 4.txt
│ │ │ └── index.html <-----
│ │ └── index.html <-----
│ └── f
│ ├── g
│ │ ├── 5.txt
│ │ └── index.html <-----
│ └── index.html <-----
├── node_modules
│ └── ...
└── package.json
Note Every folder inside the dist directory, excluding folders b and c, now include an empty index.html file.
btw. When you say "empty index.html files", I've taken that literally. However if you did need some html markup in each file you can assign that to the contents variable. For example:
contents = '<!DOCTYPE html>\n<html>\n<head></head>\n<body></body>\n</html>';
But I said "copy a file ..."
In which case you can change the custom Task to the following:
/**
* Custom task to copy a source `index.html` file in all folders.
*/
grunt.registerTask('copyFileToFolders', function() {
var srcFilePath = './path/to/file/to/copy/index.html';
grunt.file.expand({ filter: 'isDirectory' }, 'dist/**/*')
.forEach(function(dirPath) {
grunt.file.copy(srcFilePath, dirPath + '/index.html')
});
});
Notes:
This utilizes grunt.file.copy to copy the source file to all folders.
The pathname assigned to the srcFilePath variable should be substituted with a real pathname to the actual master index.html file that you want to copy to all folders.
As per the first example, the glob pattern passed to grunt.file.expand must be change as necessary.
I have this:
.
├── dirA
│ └── ProdA
│ ├── Brief
│ │ └── Form.xlsx
│ ├── Results
│ └── Studies
└── dirB
└── BrandB
└── ProdB
├── Brief
│ └── Form.xlsx
└── Results
and i want this:
.
├── dirA
│ └── ProdA
│ ├── Brief
│ ├── Results
│ └── Studies
│ └── Form.xlsx
└── dirB
└── BrandB
└── ProdB
├── Brief
└── Results
└── Studies
└── Form.xslx
So basically i have to find files Form.xlsx and move it from subdirectory Brief to subdirectory Studies (create it if it does not exists), both at the same level.
when i do:
find . -name '*.xlsx' -exec mv '{}' ../Studies ';'
I got:
.
├── dirA
│ └── ProdA
│ ├── Brief
│ ├── Results
│ └── Studies
└── dirB
└── BrandB
└── ProdB
├── Brief
└── Results
You shouldn't use .. to get the matched file's parent directory, use dirname instead.
find . -name "*.xlsx" -exec sh -c 'mv {} "$(dirname $(dirname {}))/Studies/"' \;
Have a try! :)
To make Artifactory as self-service as possible for our users, giving permissions to users to deploy to parts of repositories using their personal or team accounts, I'm trying to figure out how to configure this.
For readable directory structure based repositories like anything in the java world, the Permission Targets work perfectly (https://www.jfrog.com/confluence/display/RTF/Managing+Permissions). But I can't find any docs on how to use this for non-human-predicatable/readable directory structures, like PIP, or the flat directory structure, like NPM.
In the java world, repositories have a nicely structured tree like:
~/.m2/repository$ tree org/ | head -20
org/
├── antlr
│ ├── antlr4-master
│ │ └── 4.7.1
│ │ ├── antlr4-master-4.7.1.pom
│ │ ├── antlr4-master-4.7.1.pom.sha1
│ │ └── _remote.repositories
│ └── antlr4-runtime
│ └── 4.7.1
│ ├── antlr4-runtime-4.7.1.jar
│ ├── antlr4-runtime-4.7.1.jar.sha1
│ ├── antlr4-runtime-4.7.1.pom
│ ├── antlr4-runtime-4.7.1.pom.sha1
│ └── _remote.repositories
├── apache
│ ├── ant
│ │ ├── ant
│ │ │ ├── 1.10.1
│ │ │ │ ├── ant-1.10.1.jar
│ │ │ │ ├── ant-1.10.1.jar.sha1
For example, to give teamantl permission to only read, annotate, and write to org/antlr/antlr4-master/**, the following json can be PUT to Artifactory REST API (PUT /api/security/permissions/{permissionTargetName})
{
"includesPattern": "org/antlr/antlr4-master/**",
"repositories": [
"libs-release-local",
"libs-snapshot-local"
],
"principals": {
"groups" : {
"teamantl": ["r","n","w"]
}
}
}
But for example a pip repo is completely hashed:
Which is completely useless in the permission target "includesPattern".
How should this (Permission Targets) work for repo's like PIP, and NPM?
Your screenshot shows a virtual PyPI repo, which is generated and thus hash-structured.
Normally, these are backed by physical repos, filled using twine upload and thus having a ‹pkg›/‹version›/‹file› structure – i.e. perfectly usable as permission targets with package granularity.
I want to include only directories named *cache*, and all files and subdirectories under them.
How to write rync --include --exclude?
source dest
├── a │
├── b ├── b
│ └── d │ └── d
│ └── e │ └── e
│ └── cache │ └── cache
├── c ├── c
│ └── f │ └── f
│ └── npm_cache │ └── npm_cache
├── g ├── g
│ └── cache_stores │ └── cache_stores
├── h ├── h
│ └── cache │ └── cache
│ └── i │ └── i
│ └── j │ └── j
└── k │
└── l │
This should work:
--include='*/'
--include='*cache*/**'
--exclude='*'
--prune-empty-dirs
That says:
Include all folders (this is necessary to search inside them).
Include all files with "cache" in the name of a parent directory.
Exclude everything else.
Prune away any folders that were copied but turned out to contain no caches. Unfortunately, this also removes any empty folders within cache directories, but hopefully that's not important to you.
I have accepted ams's answer, but if you don't know rsync --include --exclude syntax (I don't), get an explicit file list with find first.
cd source
find . | grep /.*cache.*/ | rsync --files-from=- source dest