Browse Source

Initial push

master
Micah Halter 2 years ago
parent
commit
b1b5ded8b0
Signed by: mehalter GPG Key ID: 4224A6EA9A8CAAA8
  1. 8
      .gitignore
  2. 7
      Project.toml
  3. 21
      README.md
  4. 122
      src/BaseDirectory.jl
  5. 5
      src/XDG.jl

8
.gitignore

@ -24,3 +24,11 @@ docs/site/
# environment.
Manifest.toml
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

7
Project.toml

@ -0,0 +1,7 @@
name = "XDG"
uuid = "fe33d248-b583-4bd1-8106-a6949c99f4d9"
authors = ["Micah Halter <micah@mehalter.com>"]
version = "0.1.0"
[compat]
julia = "1.0"

21
README.md

@ -1,2 +1,23 @@
# XDG.jl
This package currently contains:
- Implementation of the XDG-Base-Directory Standard
http://standards.freedesktop.org/basedir-spec/
TODO:
- Implementation of the XDG-Desktop Standard
http://standards.freedesktop.org/desktop-entry-spec/
- Implementation of the XDG-Menu Standard
http://standards.freedesktop.org/menu-spec/
- Implementation of the XDG-Icon-Theme Standard
http://standards.freedesktop.org/icon-theme-spec/
- Implementation of the XDG-Shared MIME-info Database
http://standards.freedesktop.org/shared-mime-info-spec/
- Implementation of the XDG-Recent File Storage Specification
http://standards.freedesktop.org/recent-file-spec/

122
src/BaseDirectory.jl

@ -0,0 +1,122 @@
""" BaseDirectory
This module provides a way for applications to locate
shared data and configureation based on
https://specifications.freedesktop.org/basedir-spec/latest/
(based on version 0.7)
"""
module BaseDirectory
export xdg_data_home, xdg_data_dirs, xdg_config_home, xdg_config_dirs,
xdg_cache_home, save_config_path, save_data_path, save_cache_path,
load_config_paths, load_data_paths, get_runtime_dir
xdg_data_home = get(ENV, "XDG_DATA_HOME", joinpath(Sys.homedir(), ".local", "share"))
xdg_data_dirs = [xdg_data_home;
filter(!isempty, split(get(ENV, "XDG_DATA_DIRS", "/usr/local/share:/usr/share"), ":"))]
xdg_config_home = get(ENV, "XDG_CONFIG_HOME", joinpath(Sys.homedir(), ".config"))
xdg_config_dirs = [xdg_config_home;
filter(!isempty, split(get(ENV, "XDG_CONFIG_DIRS", "/etc/xdg"), ":"))]
xdg_cache_home = get(ENV, "XDG_CACHE_HOME", joinpath(Sys.homedir(), ".cache"))
"""
save_path(base, resource...)
helper function to ensure path exists from a specific base directory
"""
function save_path(base, resource...)
resource = joinpath(resource...)
@assert(!startswith(resource, "/"), "path cannot be absolute")
path = joinpath(base, resource)
mkpath(path)
return path
end
"""
save_config_path(resource...)
Ensure `\$XDG_CONFIG_HOME/<resource>/` exists, and return its path.
'resource' should normally be the name of your application. Use
this when saving configuration settings.
"""
save_config_path(resource...) = save_path(xdg_config_home, resource...)
"""
save_data_path(resource...)
Ensure `\$XDG_DATA_HOME/<resource>/` exists, and return its path.
'resource' should normally be the name of your application or a
shared resource. Use this when saving or updating application data.
"""
save_data_path(resource...) = save_path(xdg_data_home, resource...)
"""
save_cache_path(resource...)
Ensure `\$XDG_CACHE_HOME/<resource>/` exists, and return its path.
'resource' should normally be the name of your application or a
shared resource.
"""
save_cache_path(resource...) = save_path(xdg_cache_home, resource...)
"""
load_paths(bases::Array{String}, resource...)
helper function to load the same subdirectories from a list of base directories
"""
load_paths(bases, resource...) = Channel() do c
resource = joinpath(resource...)
for dir in bases
path = joinpath(dir, resource)
if ispath(path)
push!(c, path)
end
end
end
"""
load_config_paths(resource...)
Returns an iterator which gives each directory named 'resource' in the
configuration search path. Information provided by earlier directories should
take precedence over later ones, and the user-specific config dir comes first.
"""
load_config_paths(resource...) = load_paths(xdg_config_dirs, resource...)
function load_first_config(resource...)
for config in load_config_paths(resource...)
return config
end
return Nothing
end
"""
load_data_paths(resource...)
Returns an iterator which gives each directory named 'resource' in the
application data search path. Information provided by earlier directories
should take precedence over later ones.
"""
load_data_paths(resource...) = load_paths(xdg_data_dirs, resource...)
"""
get_runtime_dir()
Returns the value of `\$XDG_RUNTIME_DIR`, a directory path.
This directory is intended for 'user-specific non-essential runtime files
and other file objects (such as sockets, named pipes, ...)', and
'communication and synchronization purposes'.
"""
function get_runtime_dir()
return ENV["XDG_RUNTIME_DIR"]
end
end

5
src/XDG.jl

@ -0,0 +1,5 @@
module XDG
include("BaseDirectory.jl")
end
Loading…
Cancel
Save