forked from merlinthered/sublime-rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #30: Install Rainmeter Skin from local directory
Added install skin from folder command
- Loading branch information
Showing
94 changed files
with
6,963 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import urllib.request | ||
|
||
|
||
def download_from_to(from_location, to_file_path): | ||
# urllib.request.urlretrieve('http://example.com/big.zip', 'file/on/disk.zip') | ||
urllib.request.urlretrieve(from_location, to_file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import http.client | ||
|
||
|
||
def __is_online(domain, sub_path, response_status, response_reason): | ||
conn = http.client.HTTPSConnection(domain, timeout=1) | ||
conn.request("HEAD", sub_path) | ||
response = conn.getresponse() | ||
conn.close() | ||
|
||
return (response.status == response_status) and (response.reason == response_reason) | ||
|
||
|
||
def is_rm_doc_online(): | ||
return __is_online("docs.rainmeter.net", "/manual-beta/", 200, "OK") | ||
|
||
|
||
def is_gh_online(): | ||
return __is_online("github.com", "/", 200, "OK") | ||
|
||
|
||
def is_gh_raw_online(): | ||
""" | ||
Check if the raw content delivery from Github is online. | ||
It is routed to 301 and Moved Permanently because per standard it is routed to github.com | ||
because it natively only accepts real content paths. | ||
We do not follow reroutes else it would be 200 OK on github.com but we already have another method to check for that | ||
and Github.com is on a different service than the content delivery. | ||
""" | ||
return __is_online("raw.githubusercontent.com", "/", 301, "Moved Permanently") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# def find_ | ||
import os | ||
import re | ||
import shutil | ||
|
||
from ..path.skin_path_provider import get_cached_skin_path | ||
|
||
|
||
def check_skin_folder_already_exists(skin_folder): | ||
skins_folder = get_cached_skin_path() | ||
inis = find_inis_in_folder(skin_folder) | ||
skin_name = os.path.basename(common_path(inis)) | ||
target_skin_folder = os.path.join(skins_folder, skin_name) | ||
|
||
return os.path.exists(target_skin_folder) | ||
|
||
|
||
def install_skin_folder_into_skins_folder(skin_folder, overwrite=False): | ||
skins_folder = get_cached_skin_path() | ||
|
||
inis = find_inis_in_folder(skin_folder) | ||
skin_name = os.path.basename(common_path(inis)) | ||
resources_folders = find_resources_folders_in_folder(skin_folder) | ||
|
||
paths = [] | ||
paths.extend(inis) | ||
paths.extend(resources_folders) | ||
|
||
target_skin_folder = os.path.join(skins_folder, skin_name) | ||
|
||
transposed_paths = transpose_paths(paths, target_skin_folder) | ||
|
||
return transposed_paths | ||
|
||
|
||
# todo: problem because I mix files and folders -> easier to just transpose folders thus we need only copytree | ||
def transpose_paths(paths, target): | ||
commoner = common_path(paths) | ||
|
||
return shutil.copytree(commoner, target) | ||
|
||
|
||
def common_path(paths): | ||
""" | ||
Find skin root folder. | ||
The root folder is defined as the parent folder of the @Resources folder. | ||
Since this one is optional the next solution would be to use the least common parent from all inis | ||
""" | ||
return os.path.dirname(os.path.commonprefix([p + os.path.sep for p in paths])) | ||
|
||
|
||
def find_resources_folders_in_folder(folder): | ||
resources = [] | ||
for root, dirs, files in os.walk(folder): | ||
for dir in dirs: | ||
if dir.lower() == "@resources": | ||
resources.append(os.path.join(os.path.abspath(root), dir)) | ||
|
||
return resources | ||
|
||
|
||
def find_resources_folder_in_folder(folder): | ||
for root, dirs, files in os.walk(folder): | ||
for dir in dirs: | ||
if dir.lower() == "@resources": | ||
return os.path.join(os.path.abspath(root), dir) | ||
|
||
|
||
NAME_PATTERN = re.compile(r"^\s*Name=(.+)$", re.IGNORECASE) | ||
|
||
|
||
def find_skin_name_in_inis(inis): | ||
""" | ||
Retrieve skin name in a configuration. | ||
A configuration can contain multiple skins. | ||
Each of them can contain a metadata with its real name, | ||
since due to the copying or zipping it could be skewed | ||
with informations like master or versioning. | ||
""" | ||
for ini in inis: | ||
with open(ini, 'r') as ini_file_handler: | ||
for line in ini_file_handler: | ||
match = NAME_PATTERN.match(line) | ||
if match: | ||
return match.group(1) | ||
|
||
|
||
def find_inis_in_folder(folder): | ||
""" | ||
Retrieve path of every file ending with .ini in folder. | ||
Returns the absolute path of each found file. | ||
""" | ||
inis = [] | ||
|
||
for root, dirs, files in os.walk(folder): | ||
for fil in files: | ||
if fil.endswith('.ini'): | ||
inis.append(os.path.join(os.path.abspath(root), fil)) | ||
|
||
return inis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
def install_skin_zip_into_skins_folder(skin_zip): | ||
pass |
Empty file.
Empty file.
Oops, something went wrong.