Sharing directory on windows using Python3 - winapi

Is there a package in Python3, which can check if a windows directory is shared? and also to share a windows directory?
I am aware of using 'net share' command, I would like to know if there are is a pythonic way of doing it

For check and add, you could use NetShareCheck and NetShareAdd.
And here is an sample to use netapi in python.
Or Use winapi SHGetFileInfo with SHGFI_ATTRIBUTES, then check the dwAttributes flag for SFGAO_SHARE.
You could create it with class Win32_Share and its Create method
import wmi
c = wmi.WMI()
c.Win32_Share().Create(args)

Related

Downloading data from a shared google drive link in google colab

I want to download data from google drive link shared by someone using google colab. I am a new user of colab and I don't know how to do that.
the links are
x_train: https://drive.google.com/open?id=1cUaIEd9-MLJHFGjLz5QziNvfBtYygplX
y_train: https://drive.google.com/open?id=1hv24Ufiio9rBeSqgnNoM3dr5sVGwOmBy
x_test: https://drive.google.com/open?id=1AH9lKHT5P2oQLz8SGMRPWs_M9wIM2ZRH
y_test: https://drive.google.com/open?id=1i4_azocSDuU3TcDf3OSHO1vF0D5-xMU6
Thanks in advance
You can use gdown if the file is shared publicly.
!gdown 1cUaIEd9-MLJHFGjLz5QziNvfBtYygplX
If it's shared to you only, you need to use pydrive
# Install the PyDrive wrapper & import libraries.
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
file_id = '1cUaIEd9-MLJHFGjLz5QziNvfBtYygplX'
downloaded = drive.CreateFile({'id':file_id})
downloaded.FetchMetadata(fetch_all=True)
downloaded.GetContentFile(downloaded.metadata['title'])
If they share a folder, it's too long so I made it short in my library.
!pip install kora
from kora import drive
drive.download_folder('1HvIeNhqtFVllXFWzH5NawDdnIfgGDwCK')
A great question and something that I have been working with for some time. The most seamless/ workflow friendly is using gdown.
Presently Colab has a slightly older version install which does not allow full functionality and is installed on pyton2.7 rather than Colab system python. therefore following the terminal/underlining os via `!` method, `!pip installing`:
!pip uninstall gdown -y && pip install gdown
!gdown -V
Then you can use gdown via another ! (method 1) or import gdown (method 2) if you want to use it in code:
Method 1 for whole shared folders/directories:
!gdown --folder https://drive.google.com/drive/folders/sdsldkfj...somefileid.. -O /some_parent_directory/some_child_directory
for files:
!gdown https://drive.google.com/drive/folders/sdsldkfj...somefileid.. -O /some_parent_directory/some_child_directory
Method 2 Using down via importing works as follows:
import gdown
url = 'https://drive.google.com/uc?id=0B9P1L--7Wd2vNm9zMTJWOGxobkU'
output = '20150428_collected_images.tgz'
gdown.download(url, output, quiet=False)
Pasting your google drive file/directory url in both cases.
Hope this helps <^_^>
If you have a link to someone's publicly shared file on Google Drive, you can do this in 4 mouse clicks:
Create a shortcut to this file in your Google Drive (right-click on file -> "Add shortcut to Disk")
Mount your Google drive in Colab notebook (click buttons: "Files" -> "Mount Drive")
Now you can access this file via your shortcut for !unzip/np.load/...

Workaround for an API not allowing require a specific library (luasocket) and not able to include it via moving DLL

I am using an API called Piepan, which allows me to write Lua scripts for Mumble bots. For context, it is written in Golang using an alternative mumble implementation called Gumble. Piepan scripts are executed via cmd prompt through a piepan.exe.
I can require most libraries, like inspect.lua, and I can easily require luasocket in non-piepan scripts (scripts executed via lua.exe), but if I try to require luasocket (or what I really want, a redis library that depends on luasocket), I get an error. This is less of an error and more of a missing feature from the API, which the creator acknowledges. The creator suggests to someone else with this problem that they simply use Gumble, but I cannot do that as I am only a Lua programmer.
Here's the code of me just trying to require luasocket:
local socket = require ("include-test.socket")
(I've also tried include-test.socket.core and just socket.core)
In accordance with this stackoverflow answer, I moved my files to resemble the user's own directory, so it looks like this:
Piepan folder
-piepan exe and dlls (not luasocket dlls)
-include-test (folder)
--Script for piepan
--socket.lua
--socket folder
---core.dll
Despite the directory looking how I imagine it should based on other users' Q/As, I get this error:
.\include-test\socket.lua:13: module socket.core not found:
no field package.preload['socket.core']
Lstat : The system cannot find the path specified.
GetFileAttributesEx .\socket\core.lua: The system cannot find the path specified.
GetFileAttributesEx C:\Users\Michael\piepan\lua\socket\core.lua: The system cannot find the path specified.
GetFileAttributesEx C:\Users\Michael\piepan\lua\socket\core\init.lua: The system cannot find the path specified.
GetFileAttributesEx C:\Program Files (x86)\Lua\5.1\lua\socket\core.luac: The system cannot find the path specified.,
I've also tried including the following line, inspired by this stackoverflow answer.
package.cpath = package.cpath .. ';include-test/?.dll'
to no avail.
I am looking for any available solution, whether that be moving around dlls or compiling the original Piepan w/ extra files as needed.
(To clarify, I need a workaround that allows me to require the redis library within the same script I run through piepan. Using an outside script with the redis library to then, say, launch piepan and do something there, is not helpful to me.)

Calling Python from Jython

I want to be able to graph using Matplotlib in Jython so that I can use ABAGAIL inside of Python.
ABAGAIL:
https://github.com/pushkar/ABAGAIL
Jython does not seem to support Matplotlib. But I found the following idea on how to call Python inside of Jython:
Invoking Jython from Python (or Vice Versa)
Unfortunately, I can't get the code they suggest to work:
import execnet
gw = execnet.makegateway("popen//python=python")
channel = gw.remote_exec("""
from numpy import *
a = array([2,3,4])
channel.send(a.size)
""")
for item in channel:
print item
The main problem is that python=python doesn't work. What I'm not understanding is how to actually specify the version of python (anaconda, actually) on my Windows 10 system. What do I need to setup?
Also, is there an alternative package besides matplotlib I can use with Jython to create graphs?

In windows, where to create the `.theanorc.txt` file and how to make theano able to see it?

I am trying to make thenao use gpu on windows. This tutorial suggests that I create a .theanorc directory at my home and a theanorc.txt inside it to be able to set the configuration flags before initialization.
Where to create the theanorc.txt file (i.e. how to find out where my home is?) and how to make theano able to see it?
I have tried the following script to create .theanorc and then added theanorc.txt manually inside it, but gpu was not enabled:
import os
_theano_base_dir = os.path.expanduser('~')
if not os.access(_theano_base_dir, os.W_OK):
_theano_base_dir = '/tmp'
_theano_dir = os.path.join(_theano_base_dir, '.theanorc')
if not os.path.exists(_theano_dir):
os.makedirs(_theano_dir)
theano_config_path = os.path.expanduser(os.path.join(_theano_dir, 'theanorc.txt'))
print (theano_config_path)
This printed: C:\SPB_Data\.theanorc\theanorc.txt Is C:\SPB_Data my home?
In Windows, your home directory should be C:\Users\Your_Windows_UserName. Also if you want to create the .theanorc file without the .txt extension you can use Notepad++

Redprob.ado file installation

I’m trying to use the dynamic RE panel logit model.
I downloaded the redprob.ado, redprob.hlp, redpmod_ll.ado files from Prof. Mark Stewart's website and installed as follows.
Create ado and personal folder in my C: drive.
Save those 3 files in personal folder.
Typed net set ado c:\ado\personal
Typed adopath + "c:\ado\personal”
Type ssc install redprob
But the following message came out.
ssc install: "redprob" not found at SSC, type -findit redprob-
(To find all packages at SSC that start with r, type -ssc describe r-)”
What is the way to install and use redprob?
As you noted these files should be downloaded from Mark Stewart's site, namely http://www2.warwick.ac.uk/fac/soc/economics/staff/academic/stewart/stata
The third file is called redpmod_ll.ado, and not as you originally typed.
They are not on SSC, so the ssc command is completely irrelevant. What you did is like saying "fetch me this program from Warwick" and then "and now fetch me this program from Connecticut" when it is only at Warwick.
The StataCorp recommendation is to use c:\ado\plus, but what you did should have worked.
Try it with
which redprob
and Stata should be able to find the program and tell you where it is.
If you have manually downloaded the files, simply pasting them into c:\ado\personal should do the work. Stata will automatically load commands from this folder when it starts. Create the folder if it doesn't exist.

Resources