Skip to content

Commit

Permalink
For #30: Install Rainmeter Skin from local directory
Browse files Browse the repository at this point in the history
Added install skin from folder command
  • Loading branch information
thatsIch committed Mar 9, 2017
1 parent 041f3b6 commit fd87bb6
Show file tree
Hide file tree
Showing 94 changed files with 6,963 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
!theme
!*.hidden-tmTheme

# include http
!http/

# include install package which handles installing skins
!install

# include important sublime text files
!*.sublime-build
!*.sublime-commands
Expand Down
3 changes: 2 additions & 1 deletion Rainmeter.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
{"caption": "Rainmeter: Open Skins Folder", "command": "rainmeter_open_skins_folder"},
{"caption": "Rainmeter: Pick Color", "command": "rainmeter_color_pick"},
{"caption": "Rainmeter: Refresh Current Skin", "command": "rainmeter_refresh_current_skin"},
{"caption": "Rainmeter: Refresh Rainmeter", "command": "rainmeter_refresh"}
{"caption": "Rainmeter: Refresh Rainmeter", "command": "rainmeter_refresh"},
{"caption": "Rainmeter: Install Skin from Folder", "command": "rainmeter_install_skin_from_folder"}
]
Empty file added http/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions http/content_downloader.py
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)
31 changes: 31 additions & 0 deletions http/online_checker.py
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 added install/__init__.py
Empty file.
103 changes: 103 additions & 0 deletions install/folder.py
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
4 changes: 4 additions & 0 deletions install/from_zip.py
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 added install/git.py
Empty file.
Empty file added install/github.py
Empty file.
Loading

0 comments on commit fd87bb6

Please sign in to comment.