mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
535 stars 344 forks source link

pyang command for all files in a folder - Windows OS #739

Closed jamalakhaligova closed 3 years ago

jamalakhaligova commented 3 years ago

I am trying to run pyang command for all files in a folder, I tried this command but it didn't work:

python C:\Users\admin\Documents\Project\yangproj\venv\Scripts\pyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml -p yanginp\*

@fredgan @rszwedowski

jamalakhaligova commented 3 years ago

@mbj4668 @fredgan @jozjan

wlupton commented 3 years ago

The -p option doesn't look right?

Update: -p specifies the search path doesn't it? Also, please post the error messages.

jamalakhaligova commented 3 years ago

@wlupton error message is [Errno 2] No such file or directory , I tried even full path -p C:\Users\admin\Documents\Project\yangproj\yanginp* . Path is correct I think, this command is working, but I need to run for all files in a folder: python C:\Users\admin\Documents\Project\yangproj\venv\Scripts\pyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml yanginp\first.yang yanginp\second.yang yanginp\third.yang yanginp\fourth.yang yanginp\fifth.yang

wlupton commented 3 years ago

The -p option specifies a list of directories:

  -p PATH, --path=PATH  :-separated search path for yin and yang modules

Suppose that your yanginp directory contains only the five files in your example. Then, if you do this:

pyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml -p yanginp\*

...the command shell (not the pyang tool) will expand the wildcard (probably in alphabetical order) and the pyang tool will see this:

pyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml
    -p yanginp\fifth.yang yanginp\first.yang yanginp\fourth.yang yanginp\second.yang yanginp\third.yang 

So it will think that you are setting yanginp\fifth.yang as the YANG module search path. This is a YANG file, not a directory, and is probably the cause of the error message.

You need to set the search path to include any directories that need to be searched for YANG modules that are imported by any of the files specified on the command line.

If you still have a problem, please supply the actual command and the full error message (quoted verbatim).

jamalakhaligova commented 3 years ago

After your last comment I corrected command like this: python C:\Users\admin\Documents\Project\yangproj\venv\Scripts\pyang -f sample-xml-skeleton --sample- xml-skeleton-defaults -o output.xml -p yanginp\

But it doesn't finish running.. Also I don't have only 5 yang files in yanginp folder, I have 201 yang files, that's why I want to run the command for all files in that folder. If I had small number of input files, I could run the command manually for those.

Then I used --verbose, to see if it really runs my yang files, but no I waited for a while it doesn't.. # module search path: yanginp\;.;C:\Users\admin\Documents\Project\yangproj\venv\share\yang\modules

I decided to optimize path, so I gave full path: python C:\Users\admin\Documents\Project\yangproj\venv\Scripts\pyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml --verbose -p C:\Users\admin\Documents\Project\yangproj\yanginp\

Still, it doesn't finish running.. # module search path: C:\Users\admin\Documents\Project\yangproj\yanginp\;.;C:\Users\admin\Documents\Project\yangproj\venv\share\yang\modules

wlupton commented 3 years ago

Yes I understand that you have more than five files. I was just using your example! If this is your complete command line:

python C:\Users\admin\Documents\Project\yangproj\venv\Scripts\pyang
    -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml -p yanginp\

...then you're not supplying any YANG files, and so it'll be reading standard input. You need to supply the path (for any imported modules) AND a list of files to process.

The following command might work (you might not need the -p option; it depends on your YANG). Yes, use of the -v option to see which files are being read is indeed a good idea.

python C:\Users\admin\Documents\Project\yangproj\venv\Scripts\pyang
    -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml -p yanginp yanginp\*

Life might be a bit simpler if you ran the command from within the yanginp directory?

jamalakhaligova commented 3 years ago

I am going add this command in python script, so subprocess will call it, that's why I don't run within the yanginp directory.

I ran your command (python C:\Users\admin\Documents\Project\yangproj\venv\Scripts\pyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml -p yanginp yanginp\*) and there is this error message:

error yanginp\*: [Errno 22] Invalid argument: 'yanginp\\*'

Note: I am using windows OS, so maybe using "*" causes issue?

wlupton commented 3 years ago

Maybe. It depends on your command shell. I don't use Windows... but you should be able install bash (for example) or else there might be an alternative wildcard syntax for your existing shell. This isn't a pyang issue!