Skip to content

Commit f781b2b

Browse files
author
andrewluiqut
committed
1. add on_delete file_to_upload remove file from the upload list. 2. added filename prefix and suffic rules
1 parent b294fec commit f781b2b

5 files changed

Lines changed: 50 additions & 10 deletions

File tree

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,24 @@ uploader.mode: web # web or headless
8989
Determines whether the bagfile capturer provides a web interface (`web`) or no interface (`headless`). Other values will cause an error.
9090

9191
```yaml
92-
# filestore path
93-
uploader.filestore.local: /home/qcr/Insync/Bagfiles
92+
# the local filestore path where new or modified files are uploaded
93+
uploader.filestore.local: /home/qcr/Bagfiles
94+
# the target folder on the google drive
9495
uploader.filestore.remote: /Bagfiles
9596
```
9697
The `uploader.filestore.local` specifies the local directory where new files are to be detected and uploaded. Note that the uploader is only interested in _new_ files. However, touching the files can force the uploader to consider them as new files.
9798

9899
The `uploader.filestore.remote` specifies the target folder to receive the uploaded file on Google Drive.
99100

101+
```yaml
102+
# exclude files with suffixes and prefixes
103+
uploader.ignore.suffix:
104+
- .active
105+
uploader.ignore.prefix:
106+
- '~'
107+
```
108+
The two yaml keys, `uploader.ignore.suffix` and `uploader.ignore.prefix`, specify a list of suffixes and prefixes of filenames that will be ignored. To define more than one suffix or prefix, add more lines under the key as a list.
109+
100110
```yaml
101111
uploader.web.host: 0.0.0.0
102112
uploader.web.port: 8070

config/uploader_config.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22
---
33
# Operation Mode
44
uploader.mode: web # web or headless
5-
# filestore path
6-
uploader.filestore.local: /home/qcr/Insync/Bagfiles
5+
# the local filestore path where new or modified files are uploaded
6+
uploader.filestore.local: /home/qcr/Bagfiles
7+
# the target folder on the google drive
78
uploader.filestore.remote: /Bagfiles
9+
# exclude files with suffixes and prefixes
10+
uploader.ignore.suffix:
11+
- .active
12+
uploader.ignore.prefix:
13+
- '~'
814
# Upload delay
915
uploader.delay: 30 # seconds
1016
uploader.error_count.max: 5
1117
# Dash Agent (uploader) setting
1218
uploader.web.host: 0.0.0.0
1319
uploader.web.port: 8070
1420
uploader.web.launch_browser: False
15-
uploader.web.auth: True # Authentication required if web mode
1621
# Main system timers for the uploader implemented by Dash
1722
uploader.system.timer: 1 # seconds
1823
uploader.console.refresh: 5 # seconds

launch/main.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- Launch the camera monitor node first, which will launch the camera agent -->
55
<group if="$(arg run_uploader)">
66
<param name="mode" type="string" value="$(arg mode)" />
7-
<node pkg="gdrive_uploader" type="run.py" name="gdrive_uploader_node" output="screen" respawn="true" >
7+
<node pkg="gdrive_uploader" type="run.py" name="gdrive_uploader_node" output="screen" respawn="false" >
88
</node>
99
</group>
1010
</launch>

src/uploader/run.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ def __init__(self, filestore_path):
3535
self.filestore_path = filestore_path
3636
self.remote_filestore_path = CONFIG.get('uploader.filestore.remote', '/')
3737
self.uploader_delay = CONFIG.get('uploader.delay', 30)
38+
# setup ignore list
39+
self.ignore_suffix = CONFIG.get('uploader.ignore.suffix', None)
40+
if self.ignore_suffix is not None and type(self.ignore_suffix) == str:
41+
self.ignore_suffix = [self.ignore_suffix]
42+
self.ignore_prefix = CONFIG.get('uploader.ignore.prefix', None)
43+
if self.ignore_prefix is not None and type(self.ignore_prefix) == str:
44+
self.ignore_prefix = [self.ignore_prefix]
45+
46+
def is_in_ignore_lists(self, filename:str) -> bool:
47+
if self.ignore_suffix is not None and type(self.ignore_suffix) in (tuple, list):
48+
for prefix in self.ignore_suffix:
49+
if filename.endswith(prefix):
50+
return True
51+
if self.ignore_prefix is not None and type(self.ignore_prefix) in (tuple, list):
52+
for prefix in self.ignore_prefix:
53+
if filename.startswith(prefix):
54+
return True
55+
return False
3856
# The callback function when a create event occurs
3957
def on_created(self, event:FileSystemEvent):
4058
pass
@@ -44,11 +62,18 @@ def on_modified(self, event:FileSystemEvent):
4462
# if the event is from a modified file
4563
local_path = event.src_path
4664
filename = file_tools.get_filename(local_path)
65+
if self.is_in_ignore_lists(filename):
66+
return
4767
parent_path = file_tools.get_parent(local_path)
4868
sub_path = parent_path[len(self.filestore_path) + 1:] # the sub_path cannot start with '/' for os.path.join to work
4969
remote_path = os.path.join(self.remote_filestore_path, sub_path)
5070
DAO.add_upload_file(local_path, filename, remote_path, int(time.time()) + CONFIG.get('uploader.delay', self.uploader_delay))
51-
71+
# the callback function when a file is deleted
72+
def on_deleted(self, event:FileSystemEvent):
73+
if not event.is_directory:
74+
# if the event is from a file
75+
local_path = event.src_path
76+
DAO.remove_upload_file(local_path)
5277

5378
class GDriveUploader(object):
5479
def __init__(self):

src/uploader/web/dashapp_top.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _define_app(self):
6363
self._navbar_with_menu = dbc.NavbarSimple(
6464
children=[
6565
dbc.NavItem(dbc.NavLink('Console', href='/page_console')),
66-
dbc.NavItem(dbc.NavLink('DB', href='/page_db_browser')),
66+
# dbc.NavItem(dbc.NavLink('DB', href='/page_db_browser')),
6767
],
6868
brand=html.Div([html.H3(_APP_NAME), html.H6('Robotics and Autonomous Systems Group, REF, RI, Queensland University of Technology')]),
6969
brand_href='/page_console', color='#ffe6cc', className='fs-4 text')
@@ -108,8 +108,8 @@ def display_page(pathname):
108108
try:
109109
if pathname == '/page_console':
110110
page_content = self._console_page.layout()
111-
elif pathname == '/page_db_browser':
112-
page_content = self._db_browse_page.layout()
111+
# elif pathname == '/page_db_browser':
112+
# page_content = self._db_browse_page.layout()
113113
elif pathname == '/':
114114
page_content = self._console_page.layout()
115115
else: # if redirected to unknown link

0 commit comments

Comments
 (0)