www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - String import an entire directory

reply Neia Neutuladh <neia ikeran.org> writes:
At my job, I put together a database migration tool for our 
services. It scans for resources in your JAR file with an 
appropriate path, interprets them as SQL scripts, and applies 
them to the database if it hasn't been done yet.

I want to implement this in D. However, while D allows you to 
import individual files, it doesn't let you import an entire 
directory.

I can make a prebuild script to generate code for this, but I'm 
wondering: do other people find themselves needing this 
periodically? If so, I can write a DIP for it, or at least 
publish a codegen tool that other people can use.
Nov 11
next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Saturday, November 11, 2017 14:11:50 Neia Neutuladh via Digitalmars-d 
wrote:
 At my job, I put together a database migration tool for our
 services. It scans for resources in your JAR file with an
 appropriate path, interprets them as SQL scripts, and applies
 them to the database if it hasn't been done yet.

 I want to implement this in D. However, while D allows you to
 import individual files, it doesn't let you import an entire
 directory.

 I can make a prebuild script to generate code for this, but I'm
 wondering: do other people find themselves needing this
 periodically? If so, I can write a DIP for it, or at least
 publish a codegen tool that other people can use.
You could always generate a file with the list of files that you want to import and then use that to generate the import statements to import each file. If you're already doing something to generate all of these files to import, I wouldn't think that it take much to just generate a file with the list of files while you're at it. - Jonathan M Davis
Nov 11
parent reply Neia Neutuladh <neia ikeran.org> writes:
On Saturday, 11 November 2017 at 15:00:03 UTC, Jonathan M Davis 
wrote:
 You could always generate a file with the list of files that 
 you want to import and then use that to generate the import 
 statements to import each file.
That's exactly what I was talking about doing. I guess I need to work on my communication skills?
Nov 11
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Saturday, November 11, 2017 15:35:23 Neia Neutuladh via Digitalmars-d 
wrote:
 On Saturday, 11 November 2017 at 15:00:03 UTC, Jonathan M Davis

 wrote:
 You could always generate a file with the list of files that
 you want to import and then use that to generate the import
 statements to import each file.
That's exactly what I was talking about doing. I guess I need to work on my communication skills?
Well, it seemed to me that your e-mail implied that you were talking about generating code with an external script rather than simply importing a file with the list of files to import, but you weren't very specific about what your workaround for not being able to import all of the files in a directory with an import declaration was. Personally, I've never even used the ability to import the text of a file, let alone needed to import a bunch of files. So, I have no idea how common what you're trying to do is, but it does seem to me that it would be easy to work around the issue of not being able to import a directory. - Jonathan M Davis
Nov 11
prev sibling next sibling parent crimaniak <crimaniak gmail.com> writes:
On Saturday, 11 November 2017 at 14:11:50 UTC, Neia Neutuladh 
wrote:
 I can make a prebuild script to generate code for this, but I'm 
 wondering: do other people find themselves needing this 
 periodically? If so, I can write a DIP for it, or at least 
 publish a codegen tool that other people can use.
Yes, sometimes it's good to have more extended imports and compile-time possibilities to avoid tweaking dub build process, but I think, for current time language has a lot of more actual issues so it's better to leave this task for external tools.
Nov 12
prev sibling parent reply Adrian Matoga <dlang.spam matoga.info> writes:
On Saturday, 11 November 2017 at 14:11:50 UTC, Neia Neutuladh 
wrote:
 At my job, I put together a database migration tool for our 
 services. It scans for resources in your JAR file with an 
 appropriate path, interprets them as SQL scripts, and applies 
 them to the database if it hasn't been done yet.

 I want to implement this in D. However, while D allows you to 
 import individual files, it doesn't let you import an entire 
 directory.

 I can make a prebuild script to generate code for this, but I'm 
 wondering: do other people find themselves needing this 
 periodically? If so, I can write a DIP for it, or at least 
 publish a codegen tool that other people can use.
Why do you want to import files at compile time? Why can't it be done in run time, by simply reading directory with dirEntries and opening std.stdio.File for each one?
Nov 13
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Monday, 13 November 2017 at 09:27:10 UTC, Adrian Matoga wrote:
 On Saturday, 11 November 2017 at 14:11:50 UTC, Neia Neutuladh 
 wrote:
 At my job, I put together a database migration tool for our 
 services. It scans for resources in your JAR file with an 
 appropriate path, interprets them as SQL scripts, and applies 
 them to the database if it hasn't been done yet.

 I want to implement this in D. However, while D allows you to 
 import individual files, it doesn't let you import an entire 
 directory.

 I can make a prebuild script to generate code for this, but 
 I'm wondering: do other people find themselves needing this 
 periodically? If so, I can write a DIP for it, or at least 
 publish a codegen tool that other people can use.
Why do you want to import files at compile time? Why can't it be done in run time, by simply reading directory with dirEntries and opening std.stdio.File for each one?
Three is a use case. I have an application which should be translated into different languages. I created a texts.prop file. The language department will create texts_en.prop, texts_de.prop and so on. The language department will create GIT pull requests which will cause the build infrastructure to recompile my application. Any new text_**.prop should be automatically included in the build process. There is an advantage and a disadvantage of using import for this scenario. The advantage is, it was really easy to implement and in case I use non existing text keys in the coding, there is a compiler time error. But there is a major downside, although nothing is changed in any file, dub will every time recompile my application. Also my rather small application takes 4 seconds to compile due to this logic. Therefore I tend to reimplement the logic using a dub pre build script. Kind regards Andre
Nov 13
parent Adrian Matoga <dlang.spam matoga.info> writes:
On Monday, 13 November 2017 at 16:18:06 UTC, Andre Pany wrote:

 Three is a use case. (...)
Yeah, I could probably find more use cases, but from the OP's question it's not clear what would be the benefit of doing it at compile time in OP's case.
Nov 14