pytesser set path to pattern files - python-2.7

Working at the university, I am experiencing the problem of not being able to change config files like "digits" in the tessdata as I do not have admin rights. So I want to run everything from my home, creating patterns, configs and training data files there. Starting my detection like this works fine with the expected output:
tesseract ../pics/hi.png out --tessdata-dir ./tessdata digits
I.e. by setting the path from where I run tesseract. But how can I include this path (best as an absolute one) in the line where pytesser calls tesseract? It looks as follows
args = [tesseract_exe_name, input_filename, output_filename,'nobatch', '/prog/tessdata/configs/digits']
which doesn't work. Using just digits as a path draws the digits file from the common program and file archive which I do not want.
What's the way to include an absolute path here to tell tesseract where to draw the config files from? Or is that not possible? Any hints would be much appreciated!

So I think I found the answer here:
https://docs.python.org/2/library/subprocess.html#subprocess.Popen
import shlex
arg_str = 'tesseract ../pics/hi.png out --tessdata-dir ./tessdata digits'
args = shlex.arg_str
does the job, just need to be seperated strings.

Related

How do I change the sympy preview directory?

When I execute
sp.preview(expression, viewer = “file”, filename = “expression.png”)
SymPy automatically saves the preview in C:\Users\my username.
How do I change the save path?
I'm not sure if there is a canonical way to do this, but you can get the SYMPY_PATH as
from sympy.testing.tests.test_code_quality import SYMPY_PATH
and at least add that as a prefix to your filename (however your system likes paths added). If that works and puts it in the SymPy directory then you can use any path where you would like the file to go.

I wonder if I can perform data-pipeline by directory of a specific name with DataFusion

I'm using google-cloud-platform data fusion.
Assuming that the bucket's path is as follows:
test_buk/...
In the test_buk bucket there are four files:
20190901, 20190902
20191001, 20191002
Let's say there is a directory inside test_buk called dir.
I have a prefix-based bundle based on 201909(e.g, 20190901, 20190902)
also, I have a prefix-based bundle based on 201910(e.g, 20191001, 20191002)
I'd like to complete the data-pipeline for 201909 and 201910 bundles.
Here's what I've tried:
with regex path filter
gs://test_buk/dir//2019 to run the data pipeline.
If regex path filter is inserted, the Input value is not read, and likewise there is no Output value.
When I want to create a data pipeline with a specific directory in a bundle, how do I handle it in a datafusion?
If using directly the raw path (gs://test_buk/dir/), you might be getting an error when escaping special characters in the regex. That might be the reason for which you do not get any input file into the pipeline that matches your filter.
I suggest instead that you use ".*" to math the initial part (given that you are also specifying the path, no additional files in other folders will match the filter).
Therefore, I would use the following expressions depending on the group of files you want to use (feel free to change the extension of the files):
path = gs://test_buk/dir/
regex path filter = .*201909.*\.csv or .*201910.*\.csv
If you would like to know more about the regex used, you can take a look at (1)

How do you get the names of all gif images in a folder in python 2?

I have a folder like C:\Temp\My Pictures and it has a bunch of gif pictures in it. I need to be able to get the name of the gif images in a string and I have no idea how. I looked everywhere and couldn't find an answer, please help!
Try using:
import os
for file in os.listdir("C:\Temp\My Pictures"):
if file.endswith(".gif"):
print file
You can read more, about os.listdir at the official docs here.
As PotatoIng_ is correct you may want to end up with a list of strings.
Try using this (works with Python 2 and 3):
import os
root, dirs, files=next(os.walk('C:\Temp\My Pictures'))
gifs=list(filter(lambda filename:filename.endswith('.gif'), files))
os.walk walks down the directory tree, but you only need the first result( that's the next). Now filter the files list and use those entries with filename.endswith('.gif') is True. filter returns an iterator in python 3 so use list to turn it into a list.
Result will be e.g.:
>>> gifs
['a.gif', 'b.gif', 'c.gif']

CakePHP 3.x, How to get full path to a template file

I've tried $this->viewBuilder()->templatePath(), but this only returns the prefix and controller name. (ex. Dashboard/Users)
The full path is more like /usr/local/var/www/mysite/vendor/vendorname/users/src/Template/Dashboard/Users
I've tried a few other things like Plugin::path($this->viewBuilder()->plugin()) to get part of that path, but I have yet to find any piece of code that will return the settings for what the src folder is called and what the Template folder is called.
I could hard code them as 'src' . DS . 'Template', but was hoping I'd find something that would work even if those were changed through some config setting somewhere. (Ideally there would just be a viewBuilder->absoluteTemplatePath() or something like it.)
You can retrieve possible template paths via App::path().
If you want to retrieve the template path for your Users plugin, then you could do
$templatesPath = current(\Cake\Core\App::path('Template', 'Users'));
This would give you something like
/usr/local/var/www/mysite/vendor/vendorname/users/src/Template/
It should be noted that this method doesn't necessarily return only a single path, it does so for plugin templates though.
If you need the path to an actual file, then you'll have to concatenate the remaining path segments on your own.
See also
API > \Cake\Core\App::path()

filesyncprovider creates folders for documents with same name as document

I am building a sync app with a customprovider and a filesyncprovider. I based my provider on this example:
https://code.msdn.microsoft.com/File-Sync-with-Simple-c497bf87
Now I want to extend to a hierarchical folderstructure. So in the EnumerateItems method of the custom syncprovider I return all files and folders just like I did before with only the files in the directory. Now on the filesyncprovider side, this results in a creation of folders with the name of the file and the file being placed in this folder. E.g.
Folder1\textfile.txt\textfile.txt
I have no idea, what I am doing wrong and I find it hard to know the part of the MS filesyncprovider where I could debug to see, what's happening.
My question is, what am I doing wrong and how can I correct it, so that the correct output would be
Folder1\textfile.txt?
Best regards,
Tobias
// Must return the relative path without the filename
public string RelativeDirectoryPath
{
get
{
return _relativeFilePath;
}
Read first - then ask: I returned the path to the file instead of the path to the folder... comment above even warns not to do that...