Yeoman - How to extract zipped files in generator? - yeoman

I want to build a Yeoman generator that needs to unzip a file.
From their documentation, it seems this process is done using this.registerTransformStream(...). It says it accept any gulp plugin, so I tried gulp-unzip (link)
Here's my code:
// index.js
...
writing: function() {
var source = this.templatePath('zip'); // the folder where the zipped file is
var destination = this.destinationRoot();
this.fs.copy(source, destination);
this.registerTransformStream(unzip() );
}
...
The result seems promising, first it shows all the file list then I get Error: write after end error.
Here's the dump:
create license.txt
create readme.html
create config.php
...
...
events.js:141
throw er; // Unhandled 'error' event
^
Error: write after end
at writeAfterEnd (C:\Users\myname\Documents\project\generator-test\node_modules\gulp-unzip\node_modules\readable-stream\lib\_stream_writable.js:144:12)
at Transform.Writable.write (C:\Users\myname\Documents\project\generator-test\node_modules\gulp-unzip\node_modules\readable-stream\lib\_stream_writable.js:192:5)
at DestroyableTransform.ondata (C:\Users\myname\Documents\project\generator-test\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:531:20)
at emitOne (events.js:77:13)
at DestroyableTransform.emit (events.js:169:7)
at readableAddChunk (C:\Users\myname\Documents\project\generator-test\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:198:18)
at DestroyableTransform.Readable.push (C:\Users\myname\Documents\project\generator-test\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:157:10)
at DestroyableTransform.Transform.push (C:\Users\myname\Documents\project\generator-test\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:123:32)
at DestroyableTransform._transform (C:\Users\myname\Documents\project\generator-test\node_modules\mem-fs-editor\lib\actions\commit.js:34:12)
at DestroyableTransform.Transform._read (C:\Users\myname\Documents\project\generator-test\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:159:10)
The destination folder is empty after this. It seems the stream is trying to write the unzipped file but failed.
Does anyone solved this problem before? Or is there alternative way by just using the built-in fs?
Thanks a lot

Related

Flopy error: Cannot find gridgen binary executable

Trying to call gridgen executable file using below codes:
# use of gridgen # https://github.com/modflowpy/flopy/blob/5fcf9709ec8a655106c57d55657c47b1d4987812/examples/Notebooks/flopy3_gridgen.ipynb
# setup the active domain
from flopy.utils.gridgen import Gridgen
# Check and make sure the data folder exists.
if not os.path.exists(model_ws):
os.makedirs(model_ws)
gridgen_ws = os.path.join(model_ws, 'gridgen')
if not os.path.exists(gridgen_ws):
os.makedirs(gridgen_ws)
print('Model workspace is : {}'.format(model_ws))
print('Gridgen workspace is : {}'.format(gridgen_ws))
# **Getting an error while executing below code**
g = Gridgen(dis, model_ws=gridgen_ws)
Error: raise Exception("Cannot find gridgen binary executable")
Exception: Cannot find gridgen binary executable
Copied the code from: https://github.com/chenmingzhang/ewatering/blob/main/modflow_planar_2D/ewatering_mf6_jupytext.py.
From line 504 to 516 & line 541.
I have downloaded GRIDGEN to the indicated folder, then tried changing paths names, replacing all kinds of slashes, but can't resolve the issue.
Followed this video, but there isn't much explained about gridgen
So, please help..

Error when running near indexer localnet, fail to generate config.json

So I'm trying to run the indexer on localnet following the official tutorial https://docs.near.org/docs/tutorials/near-indexer
However when I run cargo run -- init to generate the localnet json config I get this error
Finished dev [unoptimized + debuginfo] target(s) in 17.62s
Running `target/debug/example-indexer init`
thread 'main' panicked at 'Failed to deserialize config: Error("expected value", line: 1, column: 1)', /home/francois/.cargo/git/checkouts/nearcore-5bf7818cf2261fd0/a44be20/nearcore/src/config.rs:499:39
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
At some point it seems the json is not created or not created properly I guess, the function crashing in config.rf line 499 is
impl From<&str> for Config {
fn from(content: &str) -> Self {
serde_json::from_str(content).expect("Failed to deserialize config")
}
}
It's quite difficult to debug since cargo run -- init is using some inner near function (also I'm new to rust).
the config.json file is created but it seems the permission are not set properly by the script, the content of config.json is
"<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message> ... "
If anyone from the community has encountered this problem or has a hint it would be great!! thanks a lot !
In the tutorial you referenced, it mentions a similar error, and suggests the following:
Open your config.json located in the .near folder in the root of your home directory. ( ~/.near/config.json )
In this file, locate: "tracked_shards": [] and change the value to [0].
Save the file and try running your indexer again.
So I had the wrong config with download_config: false,
It should be download_config: false, for the localnet use

Docker, ENOENT: no such file or directory

I have a Storage constant that is used in a file called listingController.js
const storage = Storage({
keyFilename: "../key/keyname.json"
});
Everything works fine when I'm not using Docker but after I create a Docker image and deploy it on server I get the following error:
ENOENT: no such file or directory, open '/key/keyname.json'
at wrapError (/app/node_modules/gcs-resumable-upload/build/src/index.js:17:12)
at /app/node_modules/gcs-resumable-upload/build/src/index.js:235:19
at getToken (/app/node_modules/google-auto-auth/index.js:27:9)
at getAuthClient (/app/node_modules/google-auto-auth/index.js:233:9)
at <anonymous>
Here I see a problem that the '..' is ignored in front of the path which is why I think that file is not found.
Here is my project structure:
src
--- key
----- keyname.json
----- firebasekeyfilename.json
--- controller
----- listingController.js
----- firebaseController.js
I have tried all different combinations of file names and paths but I cannot get it to find that file.
Does anyone have a clue why this is happening?
In my firebaseController I have the following reference to a similar file in the same folder and it works fine.
var serviceAccount = require("../key/firebasekeyfilename");
The only difference is that the path is inside require() and I guess that requires a different path.
Been stuck with this for a couple of days now, any pointers would be appreciated, thank!

How To Require Lua Socket?

I'm very new to lua development with file manipulation, and now trying to import the lua socket package into my project according to this post, but I can't run even the code below.
I guess the error message indicates I need to import not only the socket.lua but also .\socket\core (probably .dll, since it doesn't have core.lua), while a reply at the post suggested importing only the file.
I'm stuck in just the beginning... What do I have to do for the next step?
local function main()
local socket = require("socket")
end
main()
Exception in thread "main" com.naef.jnlua.LuaRuntimeException: ...n32.win32.x86_64\workspace\TestForCiv\src\socket.lua:13: module 'socket.core' not found:
no field package.preload['socket.core']
no file '.\socket\core.lua'
no file 'C:\Program Files\Java\jre1.8.0_151\bin\lua\socket\core.lua'
no file 'C:\Program Files\Java\jre1.8.0_151\bin\lua\socket\core\init.lua'
...(a bunch of no file errors continues)
Edit: I added the folder structure. Even I add the .dll file it returns the same error.
I don't know the details of you configuration, but try this
require ("src.socket")
you should require a module from the root path of the lib

symfony/yaml backed symfony/config not parsing environment variables

I have recreated a simple example in this tiny github repo. I am attempting to use symfony/dependency-injection to configure monolog/monolog to write logs to php://stderr. I am using a yaml file called services.yml to configure dependency injection.
This all works fine if my yml file looks like this:
parameters:
log.file: 'php://stderr'
log.level: 'DEBUG'
services:
stream_handler:
class: \Monolog\Handler\StreamHandler
arguments:
- '%log.file%'
- '%log.level%'
log:
class: \Monolog\Logger
arguments: [ 'default', ['#stream_handler'] ]
However, my goal is to read the path of the log files and the log level from environment variables, $APP_LOG and LOG_LEVEL respectively. According to The symphony documentations on external paramaters the correct way to do that in the services.yml file is like this:
parameters:
log.file: '%env(APP_LOG)%'
log.level: '%env(LOGGING_LEVEL)%'
In my sample app I verified PHP can read these environment variables with the following:
echo "Hello World!\n\n";
echo 'APP_LOG=' . (getenv('APP_LOG') ?? '__NULL__') . "\n";
echo 'LOG_LEVEL=' . (getenv('LOG_LEVEL') ?? '__NULL__') . "\n";
Which writes the following to the browser when I use my original services.yml with hard coded values.:
Hello World!
APP_LOG=php://stderr
LOG_LEVEL=debug
However, if I use the %env(VAR_NAME)% syntax in services.yml, I get the following error:
Fatal error: Uncaught UnexpectedValueException: The stream or file "env_PATH_a61e1e48db268605210ee2286597d6fb" could not be opened: failed to open stream: Permission denied in /var/www/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107 Stack trace: #0 /var/www/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array) #1 /var/www/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array) #2 /var/www/vendor/monolog/monolog/src/Monolog/Logger.php(532): Monolog\Logger->addRecord(100, 'Initialized dep...', Array) #3 /var/www/html/index.php(17): Monolog\Logger->debug('Initialized dep...') #4 {main} thrown in /var/www/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107
What am I doing wrong?
Ok you need a few things here. First of all you need version 3.3 of Symfony, which is still in beta. 3.2 was the released version when I encountered this. Second you need to "compile" the environment variables.
Edit your composer.json with the following values and run composer update. You might need to update other dependencies. You can substitute ^3.3 with dev-master.
"symfony/config": "^3.3",
"symfony/console": "^3.3",
"symfony/dependency-injection": "^3.3",
"symfony/yaml": "^3.3",
You will likely have to do this for symfony/__WHATEVER__ if you have other symfony components.
Now in you're code after you load your yaml configuration into your dependency container you compile it.
So after you're lines here (perhaps in bin/console):
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . DIRECTORY_SEPARATOR . '..'));
$loader->load('services.yml');
Do this:
$container->compile(true);
Your IDE's intellisense might tell you compile takes no parameters. That's ok. That's because compile() grabs its args indirectly via func_get_arg().
public function compile(/*$resolveEnvPlaceholders = false*/)
{
if (1 <= func_num_args()) {
$resolveEnvPlaceholders = func_get_arg(0);
} else {
. . .
}
References
Github issue where this was discussed
Pull request to add compile(true)
Using this command after loading your services.yaml file should help.
$containerBuilder->compile(true);
given your files gets also validated by the checks for proper configurations which this method also does. The parameter is $resolveEnvPlaceholders which makes environmental variables accessible to the yaml services configuration.

Resources