Sync
This module contains the configuration object for the sync package. The attributes of this configuration object correspond with the "sync" key of config.yaml
SyncConfig
Bases: BaseConfigFormatter
Configuration object for the sync package.
Source code in djtools/sync/config.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
__init__(*args, **kwargs)
Constructor.
Raises:
Type | Description |
---|---|
ValueError
|
Both include and exclude dirs can't be provided at the same time. |
RuntimeError
|
aws_profile must be set. |
Source code in djtools/sync/config.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
This module is responsible for syncing tracks between "usb_path" and the Beatcloud (upload and download). It also handles uploading the collection located at "collection_path" and downloading the collection uploaded to the Beatcloud by "import_user" before modifying it to point to track locations at "usb_path".
download_collection(config)
This function downloads the collection of "import_user".
After downloading "import_user"'s collection, the location of all the tracks are modified so that they point to user's "usb_path".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
Source code in djtools/sync/sync_operations.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
download_music(config, beatcloud_tracks=None)
This function syncs tracks from the Beatcloud to "usb_path".
If "download_spotify_playlist" is set to a playlist name that exists in "spotify_playlists.yaml", then "download_include_dirs" will be populated with tracks in that playlist that match Beatcloud tracks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
beatcloud_tracks
|
Optional[List[str]]
|
List of track artist - titles from S3. |
None
|
Source code in djtools/sync/sync_operations.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
upload_collection(config)
This function uploads "collection_path" to the cloud.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
Source code in djtools/sync/sync_operations.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
upload_music(config)
This function syncs tracks from "usb_path" to the Beatcloud.
"aws_use_date_modified" can be used in order to re-upload tracks that already exist in the Beatcloud but have been modified since the last time they were uploaded (i.e. ID3 tags have been altered).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
Source code in djtools/sync/sync_operations.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
This module contains helper functions used by the "sync_operations" module. Helper functions include formatting "aws s3 sync" commands, formatting the output of "aws s3 sync" commands, posting uploaded tracks to Discord, and modifying import_user's collection to point to tracks located at "usb_path".
parse_sync_command(_cmd, config, upload=False)
Appends flags to "aws s3 sync" command. If "_include_dirs" is specified, all directories are ignored except those specified. If "_exclude_dirs" is specified, all directories are included except those specified. Only one of these can be specified at once. If "aws_use_date_modified", then tracks will be re-downloaded / re-uploaded if their date modified at the source is after that of the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_cmd
|
str
|
Partial "aws s3 sync" command. |
required |
config
|
BaseConfig
|
Configuration object. |
required |
upload
|
Optional[bool]
|
Whether uploading or downloading. |
False
|
Returns:
Type | Description |
---|---|
str
|
Fully constructed "aws s3 sync" command. |
Source code in djtools/sync/helpers.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
rewrite_track_paths(config, other_user_collection)
This function modifies the location of tracks in a collection.
This is done by replacing the "usb_path" written by "import_user" with the "usb_path" in "config.yaml".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
other_user_collection
|
Path
|
Path to another user's collection. |
required |
Source code in djtools/sync/helpers.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
run_sync(_cmd, bucket_url)
Runs subprocess for "aws s3 sync" command. Output is collected and formatted such that uploaded tracks are grouped by their directories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_cmd
|
str
|
"aws s3 sync" command. |
required |
bucket_url
|
str
|
URL to an AWS S3 API compliant bucket. |
required |
Raises:
Type | Description |
---|---|
CalledProcessError
|
raised if "aws s3 sync" command fails. |
RuntimeError
|
raised if any other exception occurs while syncing. |
Returns:
Type | Description |
---|---|
str
|
Formatted list of uploaded tracks; tracks are grouped by directory. |
Source code in djtools/sync/helpers.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
upload_log(config, log_file)
This function uploads "log_file" to the "user" logs folder in S3. It then deletes all files created more than one day ago.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
log_file
|
Path
|
Path to log file. |
required |
Source code in djtools/sync/helpers.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
webhook(url, content_size_limit=2000, content=None)
Post track list of newly uploaded tracks to Discord channel associated with "url". Track list is split across multiple messages if the character limit exceed "content_size_limit".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
Discord URL for webhook. |
required |
content_size_limit
|
int
|
Character limit for Discord message; if content is larger, then multiple messages are sent. |
2000
|
content
|
Optional[str]
|
Uploaded tracks (if any). |
None
|
Source code in djtools/sync/helpers.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|