python 3 suds cache not working - caching

I'm trying to write a script for accessing Sharepoint via Python.
The following libraries have been installed: suds.jurko, ntlm.
The following code succeeds, but takes close to 20 seconds:
#!/usr/bin/env python3
from suds.client import Client
from suds.transport.https import WindowsHttpAuthenticated
from suds.cache import ObjectCache
url = 'http://blah/_vti_bin/Lists.asmx?WSDL'
user = "blah"
passwd = "blah"
ntlm = WindowsHttpAuthenticated(username=user, password=passwd)
client = Client(url, transport=ntlm)
I tried adding cache:
oc = ObjectCache()
oc.setduration(days=10)
client = Client(url, transport=ntlm, cache=oc)
I see /tmp/suds created and I see cached files under there, but it looks like it just creates more files on every run, instead of using the cached files:
-rw-r--r-- 1 pchernik smsvcs 3 Feb 5 13:27 version
-rw-r--r-- 1 pchernik smsvcs 309572 Feb 5 13:27 suds-536283349122900148-document.px
-rw-r--r-- 1 pchernik smsvcs 207647 Feb 5 13:27 suds-4765026134651708722-document.px
-rw-r--r-- 1 pchernik smsvcs 21097 Feb 5 13:27 suds-1421279777216033364-document.px
-rw-r--r-- 1 pchernik smsvcs 207644 Feb 5 13:27 suds-6437332842122298485-document.px
-rw-r--r-- 1 pchernik smsvcs 309572 Feb 5 13:27 suds-3510377615213316246-document.px
-rw-r--r-- 1 pchernik smsvcs 21097 Feb 5 13:28 suds-7540886319990993060-document.px
-rw-r--r-- 1 pchernik smsvcs 207617 Feb 5 13:30 suds-1166110448227246785-document.px
-rw-r--r-- 1 pchernik smsvcs 309548 Feb 5 13:30 suds-2848176348666425151-document.px
-rw-r--r-- 1 pchernik smsvcs 21076 Feb 5 13:31 suds-6077994449274214633-document.px
Is suds normally this slow?
Any ideas on fixing the caching issues?
Are there any other python 3 libraries I can use for this instead of suds?
Any ideas / suggestions are appreciated.
Thanks,
-Pavel

I had the same issue, try setting your cachingpolicy to 1:
client = Client(url, transport=ntlm, cache=oc, cachingpolicy=1)
This will cache your WSDL objects instead of your XML files.
From suds documentation:
cachingpolicy
The caching policy, determines how data is cached. The default is 0. version 0.4+
0 = XML documents such as WSDL & XSD.
1 = WSDL object graph.
Edit: I re-read your question and realized I am missing something important; your cache is getting re-generated. I believe this is due to not specifying a location for the cache. This is from the documentation of the FileCache class in cache.py:
If no cache location is specified, a temporary default location will be
used. Such default cache location will be shared by all FileCache
instances with no explicitly specified location within the same
process. The default cache location will be removed automatically on
process exit unless user sets the remove_default_location_on_exit
FileCache class attribute to False.
So, even if you want to use the default cache location, you will need to explicitly define it when you create your cache object. This is what I've done in my code:
# Configure cache location and duration ('days=0' = infinite)
cache_dir = os.path.join(os.path.abspath(os.sep), r'tmp\suds')
self.cache = ObjectCache(cache_dir, days=0)
You could also try setting the remove_default_location_on_exit attribute as suggested in the FileCache documentation, but I have not tried this method.

I had the same issue, but I noticed the version of suds-jurko in pypi has the following function in reader.py that generates the name of the cache file:
def mangle(self, name, x):
"""
Mangle the name by hashing the I{name} and appending I{x}.
#return: the mangled name.
"""
h = abs(hash(name))
return '%s-%s' % (h, x)
In python3 hash adds a random seed to the string. This has been fixed in the current version of suds-jurko at https://bitbucket.org/jurko/suds/ by using hashlib/md5 instead. You could either install it from there instead of pypi or just edit your reader.py file and change it to
h = hashlib.md5(name.encode()).hexdigest()

Are you sure you are using suds-jourko? It resembles very much the issue described here:
Suds is not reusing cached WSDLs and XSDs, although I expect it to
You could profile your application or run it with logging enabled (like suggested in the linked question).
As an alternative you could try osa: https://pypi.python.org/pypi/osa/
Edit: Did not see you already had installed suds-jourko

Related

Where does hugging face's transformers save models?

Running the below code downloads a model - does anyone know what folder it downloads it to?
!pip install -q transformers
from transformers import pipeline
model = pipeline('fill-mask')
Update 2021-03-11: The cache location has now changed, and is located in ~/.cache/huggingface/transformers, as it is also detailed in the answer by #victorx.
This post should shed some light on it (plus some investigation of my own, since it is already a bit older).
As mentioned, the default location in a Linux system is ~/.cache/torch/transformers/ (I'm using transformers v 2.7, currently, but it is unlikely to change anytime soon.). The cryptic folder names in this directory seemingly correspond to the Amazon S3 hashes.
Also note that the pipeline tasks are just a "rerouting" to other models. To know which one you are currently loading, see here. For your specific model, pipeline(fill-mask) actually utilizes a distillroberta-base model.
As of Transformers version 4.3, the cache location has been changed.
The exact place is defined in this code section ​https://github.com/huggingface/transformers/blob/master/src/transformers/file_utils.py#L181-L187
On Linux, it is at ~/.cache/huggingface/transformers.
The file names there are basically SHA hashes of the original URLs from which the files are downloaded. The corresponding json files can help you figure out what are the original file names.
On windows 10, replace ~ with C:\Users\username or in cmd do cd /d "%HOMEDRIVE%%HOMEPATH%".
So full path will be: C:\Users\username\.cache\huggingface\transformers
As of transformers 4.22, the path appears to be (tested on CentOS):
~/.cache/huggingface/hub/
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="sentence-transformers/all-MiniLM-L6-v2", filename="config.json")
ls -lrth ~/.cache/huggingface/hub/models--sentence-transformers--all-MiniLM-L6-v2/snapshots/7dbbc90392e2f80f3d3c277d6e90027e55de9125/
total 4.0K
lrwxrwxrwx 1 alex alex 52 Jan 25 12:15 config.json -> ../../blobs/72b987fd805cfa2b58c4c8c952b274a11bfd5a00
lrwxrwxrwx 1 alex alex 76 Jan 25 12:15 pytorch_model.bin -> ../../blobs/c3a85f238711653950f6a79ece63eb0ea93d76f6a6284be04019c53733baf256
lrwxrwxrwx 1 alex alex 52 Jan 25 12:30 vocab.txt -> ../../blobs/fb140275c155a9c7c5a3b3e0e77a9e839594a938
lrwxrwxrwx 1 alex alex 52 Jan 25 12:30 special_tokens_map.json -> ../../blobs/e7b0375001f109a6b8873d756ad4f7bbb15fbaa5
lrwxrwxrwx 1 alex alex 52 Jan 25 12:30 tokenizer_config.json -> ../../blobs/c79f2b6a0cea6f4b564fed1938984bace9d30ff0

Emacs 25.2 dired mode shows .. above . How do I change this?

On my win-10 machine, dired shows this:
drwxr-xr-x 58 jkb jkb 4096 Nov 5 11:08 ..
drwxr-xr-x 6 jkb jkb 4096 Nov 6 09:34 .
Where the .. entry comes first. How do I modify the installation to change it back to this:
drwxr-xr-x 6 jkb jkb 4096 Nov 6 09:34 .
drwxr-xr-x 58 jkb jkb 4096 Nov 5 11:08 ..
It is not a big issue, except that on my mint 18 machine it shows the traditional order. Uniformity would be good.
Many thanks for pointers and advice.
[See the first comment to this question for the answer]
Formal answer:
I can solve my issue by setting ls-lisp-UCA-like-collation to nil:
'(ls-list-UCA-like-collation nil)
in the customize section of my .emacs file or via the customize menus.
The change has the side-effect of changing the ordering of the cygwin home directory, the ~/.* files come first now.
There may be another option to fix that, if it is important.
Note that this is an issue with dired on emacs, using ls-lisp.

Kernel defconfig in buildroot (arm target)

Debian 8 x64, buildroot 2016.02 / 2016-05-07 / 2016-05-13.
After make menuconfig and set some settings I run make. There is an error appears:
linux/linux.mk:424: *** No kernel defconfig name specified, check your
BR2_LINUX_KERNEL_DEFCONFIG setting. Stop.
This answer does not help: my arch/arm/configs/ folder does not exist in every release/snapshot I've tried. There is only arch folder with this content:
-rw-r--r-- 1 user user 11K May 12 19:21 Config.in
-rw-r--r-- 1 user user 176 May 12 19:21 Config.in.aarch64
-rw-r--r-- 1 user user 1.7K May 12 19:21 Config.in.arc
-rw-r--r-- 1 user user 15K May 12 19:21 Config.in.arm
-rw-r--r-- 1 user user 2.2K May 12 19:21 Config.in.bfin
-rw-r--r-- 1 user user 735 May 12 19:21 Config.in.m68k
-rw-r--r-- 1 user user 279 May 12 19:21 Config.in.microblaze
-rw-r--r-- 1 user user 2.1K May 12 19:21 Config.in.mips
-rw-r--r-- 1 user user 70 May 12 19:21 Config.in.nios2
-rw-r--r-- 1 user user 5.5K May 12 19:21 Config.in.powerpc
-rw-r--r-- 1 user user 693 May 12 19:21 Config.in.sh
-rw-r--r-- 1 user user 617 May 12 19:21 Config.in.sparc
-rw-r--r-- 1 user user 7.5K May 12 19:21 Config.in.x86
-rw-r--r-- 1 user user 1.5K May 12 19:21 Config.in.xtensa
I've tried to create arch/arm/configs/ folder and put there arch/Config.in.arm file (renamed to arm_defconfig/whatever) or empty file (renamed).
Whatever Kernel - Defconfig name I set, it does not helps.
make BR2_LINUX_KERNEL_DEFCONFIG also does not helps. Option is not documented in Buildroot user manual.
make linux-menuconfig returns same error if no Kernel - Defconfig name seted or
Can't find default configuration "arch/arm/configs/name_defconfig"!
where name is Kernel - Defconfig name variable. I've tried to set this to arm, BR2_LINUX_KERNEL_DEFCONFIG and many other names.
Can you help me, how to set default kernel configuration from buildroot developers?
The kernel defconfig is a configuration file in the kernel tree, not the buildroot tree. You have to look in arch/arm/configs in the kernel. Find the defconfig there that is appropriate for your target CPU. If you are not using an upstream kernel, you'll have to check with the vendor which defconfig to use. Remember to remove the _defconfig part of the name.
If you really have no idea at all, multi_v5 and multi_v7 are safe options: they include support for all possible processors with an ARMv5 resp. ARMv7 architecture.
You will probably encounter the same issue with the device tree. You can find the device trees (the .dts files) in arch/arm/boot/dts in the kernel tree. This one does have to match exactly with your board.

Bash - What is the best way to save the value of a quantity after the script has terminated?

I am attempting to write a script that changes my desktop wallpaper to the next picture in my ~\Picture\Wallpapers directory. I have already created a script, change_wallpaper, which can change my desktop background to any given picture.
My plan was to list all the pictures in ~\Picture\Wallpapers as an array, find the index i of the current wallpaper, and apply change_wallpaper to the i+1 element of the array of pictures. My only issue is finding a way to story the index of the current wallpaper. I could create a file which contains this value, but it seems really inelegant to just have a text file with the number 12, for example, saved somewhere in my home directory.
Is there a better way?
I agree with the general consensus of using a file to store the index of the current wallpaper. A slightly more elegant way would be to put a "." (dot) in front of the file name to keep it hidden in the directory where your script is located. Something like:
admin#myHost:/home/admin$ ls -la
total 6200
drwxrwxr-x 4 admin admin 4096 Jul 02 15:41 .
drwxr-xr-x 71 bin bin 4096 Jun 29 12:43 ..
-rw------- 1 admin admin 3939 Jun 29 16:02 .bash_history
-rw-r--r-- 1 admin admin 21 Nov 04 2014 .bashrc
-rwxr-x--x 1 admin admin 259 Oct 13 2014 .profile
-rw------- 1 admin admin 3939 Jun 29 16:02 .wallpaper_index
-rw------- 1 admin admin 3939 Jun 29 16:02 change_wallpaper
There are countless linux and unix applications that do this.

Unix - pipeline ls - la | less C executable giving double total file size vs shell

*Edit - Stephen has answered this question in the comments below *
so basically I have made two seperate child processes(using two seperate methods with their own fork) to execute the command ls -la | less using pipe.
The first one executes ls like this:
execl("/bin/ls", "ls", "-la", NULL);
The second child process executes less like this:
execlp("less", "less", NULL);
And the results come up fine.. apart from one little part:
Results using shell command:
total 15
drwxr-xr-x 2 daniel staff 4 2015-02-27 18:58 .
drwxr-xr-x 15 daniel staff 24 2015-02-27 18:58 ..
-rwxr-xr-x 1 daniel staff 9280 2015-02-27 18:58 pipes
-rw-r--r-- 1 daniel staff 1419 2015-02-27 18:58 pipes.c
Results using my executable:
total 30
drwxr-xr-x 2 daniel staff 4 Feb 27 18:58 .
drwxr-xr-x 15 daniel staff 24 Feb 27 18:58 ..
-rwxr-xr-x 1 daniel staff 9280 Feb 27 18:58 pipes
-rw-r--r-- 1 daniel staff 1419 Feb 27 18:58 pipes.c
Now the date being a different format I don't care about.. but the total size is twice as large with my executable(30 vs 15). Why is this happening?
Make sure that the ls you are running from the shell and the ls that is running in your program are the same program.
Your program is specifying /bin/ls as the program to run; you can find out what is being run when you type the command at the shell prompt by using the shell command which ls (also see type ls).
If these are different it could be due to the POSIX vs. GNU blocksize used in the total size computation.
This answer indicates that POSIX and GNU tools differ in the blocksize they use to compute the total. Try adding h to your command and compare the results (this flag makes the units explicit). My guess is that the execution environment of these processes is disturbing the result. For instance it may not be the same ls that you are running.

Resources