mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-28 21:06:45 -05:00
New blog posts
This commit is contained in:
parent
56fd5bda72
commit
2766ee1bf4
2 changed files with 55 additions and 0 deletions
17
content/blog/missinglibraries.md
Normal file
17
content/blog/missinglibraries.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
title: "Missing Libraries"
|
||||
date: 2020-02-08T20:42:50-05:00
|
||||
draft: false
|
||||
images: []
|
||||
---
|
||||
|
||||
The piwheels blog outlined a great [post](https://blog.piwheels.org/how-to-work-out-the-missing-dependencies-for-a-python-package/) on what to do when you are missing shared libraries in Python packages. Though the short of this tip is helpful on its own as well. If you are running any piece of software and its missing a library, try to find the `.so` file related to that package.
|
||||
|
||||
Then run `ldd` on that file passing it to grep to filter for not found packages:
|
||||
|
||||
```bash
|
||||
ldd file.so | grep "not found"
|
||||
```
|
||||
|
||||
And if you're on Ubuntu, then you can use `apt-file` to find the related packages.
|
||||
|
38
content/blog/recursivelisting.md
Normal file
38
content/blog/recursivelisting.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: "Quick Python: List Files Recursively"
|
||||
date: 2020-02-09T17:31:44-05:00
|
||||
draft: false
|
||||
images: []
|
||||
---
|
||||
|
||||
In order to add website files into a Flask application using setuptools, I needed to recurse down several directories and grab HTML and CSS files.
|
||||
|
||||
This Python tip will show you how to get a list of files recursively.
|
||||
|
||||
First in order to solve this problem, we're going to recursively get a list of directories.
|
||||
|
||||
```python
|
||||
from glob import glob
|
||||
directories = glob('/path/to/directory/**/', recursive=True)
|
||||
```
|
||||
|
||||
Now we will go in each directory and grab the files,
|
||||
|
||||
```python
|
||||
data_files = []
|
||||
for directory in directories:
|
||||
data_files += list(filter(lambda x: x + '/' not in directories, glob(directory + '*')))
|
||||
```
|
||||
|
||||
For setuptools, you would want the `data_files` variable to be a list of tuples with module names and the files associated with them.
|
||||
|
||||
Complete script:
|
||||
|
||||
```python
|
||||
data_files = []
|
||||
directories = glob('path/to/files/**/', recursive=True)
|
||||
for directory in directories:
|
||||
files = list(filter(lambda x: x + '/' not in directories, glob(directory + "*")))
|
||||
data_files.append((directory, files))
|
||||
```
|
||||
For setuptools don't forget to `include_package_data`!
|
Loading…
Reference in a new issue