Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom-py
Commits
09b477de
Commit
09b477de
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
support excluding paths from upload
parent
c6466493
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/djrandom_client/client.py
+17
-5
17 additions, 5 deletions
client/djrandom_client/client.py
client/djrandom_client/upload.py
+10
-1
10 additions, 1 deletion
client/djrandom_client/upload.py
with
27 additions
and
6 deletions
client/djrandom_client/client.py
+
17
−
5
View file @
09b477de
...
...
@@ -52,7 +52,7 @@ class FullScan(threading.Thread):
time
.
sleep
(
delay
)
def
run_client
(
server_url
,
music_dir
,
api_key
,
run_once
,
bwlimit
,
def
run_client
(
server_url
,
music_dir
,
excludes
,
api_key
,
run_once
,
bwlimit
,
enable_watcher
):
log
.
debug
(
'
settings: server=%s, music_dir=%s, api_key=%s,
'
'
bwlimit=%s, watcher=%s
'
%
(
...
...
@@ -66,14 +66,24 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit,
throttle
.
set_rate_limit
(
bwlimit
)
# Warn on this condition, but don't die -- the directory might exist later!
music_dir
=
os
.
path
.
realpath
(
os
.
path
.
expanduser
(
music_dir
))
if
not
os
.
path
.
isdir
(
music_dir
):
log
.
error
(
'
The music_dir you specified does not exist
'
)
# Compute absolute exclude paths.
abs_excludes
=
[]
for
exclude_prefix
in
excludes
:
if
not
exclude_prefix
.
startswith
(
'
/
'
):
exclude_prefix
=
os
.
path
.
join
(
music_dir
,
exclude_prefix
)
if
not
exclude_prefix
.
endswith
(
'
/
'
):
exclude_prefix
+=
'
/
'
abs_excludes
.
append
(
os
.
path
.
realpath
(
exclude_prefix
))
if
enable_watcher
and
not
watcher_support
:
log
.
warn
(
'
inotify/fsevents support not enabled on this platform
'
)
enable_watcher
=
False
upl
=
upload
.
Uploader
(
server_url
.
rstrip
(
'
/
'
),
api_key
)
upl
=
upload
.
Uploader
(
server_url
.
rstrip
(
'
/
'
),
api_key
,
abs_excludes
)
upl
.
setDaemon
(
True
)
# Start the full filesystem scan in the background.
...
...
@@ -130,6 +140,9 @@ def main():
parser
.
add_option
(
'
--music_dir
'
,
default
=
'
~/Music
'
,
help
=
'
Path to your music directory
'
)
parser
.
add_option
(
'
--exclude
'
,
action
=
'
append
'
,
default
=
[],
help
=
'
Exclude certain paths from scanning
'
)
parser
.
add_option
(
'
--server_url
'
,
default
=
'
https://djrandom.incal.net/receiver
'
,
help
=
'
URL to the API endpoint
'
)
...
...
@@ -148,7 +161,6 @@ def main():
if
not
opts
.
api_key
:
parser
.
error
(
'
You must specify an API Key
'
)
music_dir
=
os
.
path
.
expanduser
(
opts
.
music_dir
)
if
args
:
parser
.
error
(
'
Too many arguments
'
)
...
...
@@ -161,8 +173,8 @@ def main():
do_realtime
=
not
opts
.
no_realtime_watch
daemonize
.
daemonize
(
opts
,
run_client
,
(
opts
.
server_url
,
music_dir
,
opts
.
api_key
,
opts
.
once
,
opts
.
bwlimit
,
do_realtime
))
(
opts
.
server_url
,
opts
.
music_dir
,
opts
.
exclude
,
opts
.
api_key
,
opts
.
once
,
opts
.
bwlimit
,
do_realtime
))
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
client/djrandom_client/upload.py
+
10
−
1
View file @
09b477de
...
...
@@ -60,12 +60,13 @@ class FileDatabase(object):
class
Uploader
(
threading
.
Thread
):
def
__init__
(
self
,
server_url
,
api_key
,
db_path
=
None
,
def
__init__
(
self
,
server_url
,
api_key
,
excludes
=
[],
db_path
=
None
,
state_path
=
None
):
threading
.
Thread
.
__init__
(
self
)
self
.
api_key
=
api_key
self
.
server_url
=
server_url
self
.
queue
=
Queue
.
Queue
(
100
)
self
.
excludes
=
excludes
self
.
db_path
=
db_path
self
.
stats
=
stats
.
Stats
(
state_path
)
self
.
opener
=
urllib2
.
build_opener
(
throttle
.
ThrottledHTTPHandler
,
...
...
@@ -114,6 +115,12 @@ class Uploader(threading.Thread):
self
.
stats
.
incr
(
'
uploaded_files
'
)
log
.
info
(
'
successfully uploaded %s (%s)
'
%
(
path
,
sha1
))
def
_should_exclude
(
self
,
path
):
for
exclude_prefix
in
self
.
excludes
:
if
path
.
startswith
(
exclude_prefix
):
return
True
return
False
def
run
(
self
):
log
.
debug
(
'
starting uploader thread
'
)
db
=
FileDatabase
(
self
.
db_path
)
...
...
@@ -123,6 +130,8 @@ class Uploader(threading.Thread):
path
=
self
.
queue
.
get
()
if
path
is
None
:
break
if
self
.
_should_exclude
(
path
):
continue
if
db
.
has
(
path
):
continue
self
.
stats
.
set
(
'
uploading
'
,
path
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment