Trouble with gettext windows and domain - python

I have a problem with gettext on windows.
I'm using gettext module from python and the 3rd part module named gettext_windows:
http://bazaar.launchpad.net/~bialix/gettext-py-windows/trunk/view/head:/gettext_windows.py
THe code is the following:
gettext_windows.setup_env()
_ = gettext.gettext
self._appName = "bitbucket"
self._localeDir = os.getcwd() + "\\data\\locale\\"
self._languages = ["it_IT", "pl_PL"]
if gettext_windows.get_language()[0] in self._languages:
lang = gettext_windows.get_language()[0]
self._translation = gettext.translation(self._appName, self._localeDir, lang)
self._translation.install(unicode=True)
For create a .po/.mo files im using PoEdit.
Then i save these files and i put them in:
data
----locale/
--------it_IT/
------------LC_MESSAGES/
----------------bitbucket.mo
----------------bitbucket.po
data
----locale/
--------pl_PL/
------------LC_MESSAGES/
----------------bitbucket.mo
----------------bitbucket.po
When i trying to execute my app i have the followed error:
No translation files found for domain bitbucket
Can anybody explain me what's wrong?
THe files are in good directory.
IF i trying to user find() method from gettext module:
print gettext.find('bitbucket', self._localeDir, self._languages, all=True)
It work properly and returns *.mo files for it_IT/pl_PL language

I would recommend following the instructions on the wxPython wiki: http://wiki.wxpython.org/Internationalization#How_to_get_gettext_tools_for_Win32
If you get stuck, ask for help on the wxPython mailing list. There are multiple people there who have written this kind of support into their applications.

Related

how can I delete files with python kivy?

I am new to python kivy. I am finding a way to delete files without importing the os module. It casts an error while compiling it with buildozer.
here's my code:
def remove_all(arg):
store = JsonStore('data.json')
if store.exists('json'):
filename = int(store.get('json').get('value'))
for i in range(filename):
os.remove('results/' + str(i+1) + '.jpg')
store.delete('json')
please lemme know if there's a module of kivy for deleting files
Well, you could use shutil.rmtree(), which removes the file in question.
The real question however is, "why do I get an error with os?". OS is part of the python standard library, so buildozer adds it to your app either way. Did you include it in your buildozer .spec file?
If so, don't.

Python API for Github, getting contents in specific directory for specific branch not returning all content

Using the PyGithub API, I am attempting to retrieve all contents from a specific folder from a specific branch of a repository hosted with Github. I can't share the actual repository or specifics regarding the data, but the code I am using is this:
import github
import json
import requests
import base64
from collections import namedtuple
Package = namedtuple('Package', 'name version')
# Parameters
gh_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
header = {"Authorization": f"token {gh_token}"}
gh_hostname = 'devtopia.xxx.com'
gh = github.Github(base_url=f'https://{gh_hostname}/api/v3', login_or_token = gh_token)
repo_name = "xxxxxxxxx/SupportFiles"
conda_meta = "xxxxxxx/bin/Python/envs/xxxxxx-xx/conda-meta"
repo = gh.get_repo(repo_name)
def parse_conda_meta(branch):
package_list = []
meta_contents = repo.get_contents(conda_meta, ref=branch) #<< Returns less files than expected for
# a specified branch "xxx/release/3.2.0",
# returns expected number of files for
# "master" branch.
for i, pkg in enumerate(meta_contents):
if ".json" in pkg.name: # filter for JSON files
print(i, pkg.name)
# Need to use GitHub Data API (REST) blobs instead of easier
# `github` with `pkg.decoded_content` here because that method
# only works with files <= 1MB whereas Data API allows for
# reading files <= 100MB.
resp = requests.get(f"https://devtopia.xxxx.com/api/v3/repos/xxxxxxxxx/SupportFiles/git/blobs/{pkg.sha}?ref={branch}", headers=header)
pkg_cont = json.loads(base64.b64decode(json.loads(resp.content)["content"]))
package_list.append(Package(pkg_cont['name'], pkg_cont['version']))
else:
print('>>', i, pkg.name)
return package_list
if __name__ == "__main__":
pkgs = parse_conda_meta("xxx/release/3.2.0")
print(pkgs)
print(len(pkgs))
For some reason that I can't get to the bottom of, I am not getting the correct number of files returned by repo.get_contents(conda_meta, ref=branch). For the branch that I am specifying, when that branch is checked out I am seeing 186 files in the conda-meta folder. However, repo.get_contents(conda_meta, ref=branch) returns only 182, I am missing four JSON files.
Is there some limitation to repo.get_contents that I'm not aware of? I've been reading the doc but can't find anything that hints at the problem I am having. There is one bit about it only handling files up to 1mb, but I am seeing files larger than this returned (e.x: python is 1.204mb and is returned in the list of files). I believe this just applies to reading file content over 1mb, which I deal with by using the GitHub Data API (REST) further downstream. Is there something I'm doing wrong here?
Thanks for reading, any help with this is much appreciated!
Update with solution!
The Problem:
After some more digging, I have found the problem's cause. It's not to do with the code above or repo.get_contents(conda_meta, ref=branch) specifically. It is actually a unix/windows clash that was mistakenly introduced into our repository for this specific branch "xxx/release/3.2.0" but not present in others.
So what was the problem? NTFS (and Windows more broadly) by default is case insensitive, but Git is from a Unix world and is case-sensitive by default
We inadvertently created two folders for Python in the bin directory of the conda_meta path (xxxxxx/bin/), one folder called "Python" and one called "python" (note the lower-case). When pulling the repository locally, only the "Python" folder shows up containing all 168 files. On GitHub, however, the path with "Python" contains 182 files while the path with "python" contains the remaining 4 files.
The Solution:
Solution is to add a conda_meta_folders parameter that takes a list of paths to parse_conda_meta and search each directory. There might be a slicker solution though, I'm looking into whether it is possible to do something like git config core.ignorecase true with the PyGithub API. Does anyone know if it is possible to have PyGithub honor this or be configured for this?

Read msi with python msilib

I need to read an msi file and make some queries to it. But it looks like despite it is a standard lib for python, it has poor documentation.
To make queries I have to know database schema and I can't find any examples or methods to get it from the file.
Here is my code I'm trying to make work:
import msilib
path = "C:\\Users\\Paul\\Desktop\\my.msi" #I cannot share msi
dbobject = msilib.OpenDatabase(path, msilib.MSIDBOPEN_READONLY)
view = dbobject.OpenView("SELECT FileName FROM File")
rec = view.Execute(None)
r = v.Fetch()
And the rec variable is None. But I can open the MSI file with InstEd tool and see that File is present in the tables list and there are a lot of records there.
What I'm doing wrong?
Your code is suspect, as the last line will throw a NameError in your sample. So let's ignore that line.
The real problem is that view.Execute returns nothing of use. Under the hoods, the MsiViewExecute function only returns success or failure. After you call that, you then need to call view.Fetch, which may be what your last line intended to do.

Tagging mp3 files in python 2.7 using eyeD3

I am trying go create a taste profile for a directory of mp3 files using python 2.7 script, but it seems there's something wrong with my eyed3 module.
first I had to import it with 'd' instead of 'D'
import eyed3
then I had to change deprecated playlist method to catalog.get_item_dicts().
but now it seems that there's something wrong with THIS method:
tag = eyed3.Tag()
I know pythonis case sensitive, and have tried several syntaxes: eyeD3, tag().
but terminal logs:
>>'module' object has no attribute 'Tag'
I have followed this thread: How to get detail (Title,Artist) from .mp3 files in python using eyed3
with a similar question, but it wasn't resolved.
when script runs: python personal_catalog_scanner.py -c soup -t song mp3,
an Echonest song catalog is created, mp3 files are found, but no idis created.
what could be wrong?
The Tag class is actually eyed3.ID3.Tag, not eyed3.Tag, so you can use the following:
tag = eyed3.ID3.Tag()
...or import it beforehand:
from eyed3.id3.tag import Tag
tag = Tag()

Python - finding TTF files

Can anyone improve on this? I'm fairly new to python and am trying to write portable code. I need to locate a font file to pass to ImageDraw.Draw.Text.
import matplotlib.font_manager as fontman
def findFontFile(searchFont):
fList = fontman.findSystemFonts(fontpaths=None, fontext='ttf')
targetFont = []
for row in fList:
try:
if searchFont in row:
targetFont.append(row)
except TypeError:
pass
return targetFont[0]
On my system this gives me:
>>> findFontFile('DejaVuSans.ttf')
'/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf'
Which is exactly what I need. Does this look like it will work on Mac / Windows systems as well as Linux (tested on Linux)? Could it be done more efficiently? In a more readable style? Will Mac / Windows have a different font file naming format? Suggestions welcome.
I would do a little rewrite like (some changes are just a matter of style, more python like):
def find_font_file(query):
matches = list(filter(lambda path: query in os.path.basename(path), fontman.findSystemFonts()))
return matches
The caller would then decide the element to use (after checking permissions etc).
As for the compatibility you can view here that the lib uses a set of common directories for the "main" operating systems to search for fonts (X window manager (linux), windows and os x). But you can always pass the directories where you want to search if you have more information on the different environments where the app is going to run.
be careful when doing if searchFont in row.
If someone has username is marial, and you're searching for the font arial, by using findFontFile('arial'), your code would be getting all of the fonts installed in the user's home directory (i.e. /home/marial/.fonts).

Categories

Resources