开发者

Ubuntu One Folder Sync Filter

开发者 https://www.devze.com 2023-01-03 08:10 出处:网络
I am trying to modify the Ubuntu One File syncing python scripts to not including things like .iso\'s.

I am trying to modify the Ubuntu One File syncing python scripts to not including things like .iso's.

I have got as far as finding this file: /usr/share/pyshared/ubuntuone/u1sync/constants.py

Inside is this piece of code:

import re

# the name o开发者_高级运维f the directory u1sync uses to keep metadata about a mirror
METADATA_DIR_NAME = u".ubuntuone-sync"

# filenames to ignore
SPECIAL_FILE_RE = re.compile(".*\\.("
                             "(u1)?partial|part|"
                             "(u1)?conflict(\\.[0-9]+)?)$")

How can I edit this last section (regex?) and make it ignore .iso files??? I'm fairly sure this is the place to put it!

Pretty sure this is standard python action :)

Any help would be appreciated.

Thanks kindly.

Andy


The regex documentation for python would be the place to look that up.

For isos you could probably just add a "|.*\.iso$" to the last line.


UbuntuOne should really have a .ignore file or equally.... I want to ignore lots of stuff... .pyc, .blend1 just for start.

UPDATE: it has - take a look at:

https://answers.launchpad.net/ubuntuone-client/+question/114731

OBSOLETE ANSWER:

To answer... .*\\. is in the beginning of the old pattern, so replacing:

"(u1)?conflict(\.[0-9]+)?)$")

with:

"(u1)?conflict(\.[0-9]+)?|iso)$")

Should do it.

Listing strings after each other in Python is just concatenating them so it's all one string.


The regex to match iso files would be

".*\\.iso$"

Which is match anything ending with ".iso"

I think you can add that as another line in the re.compile call but someone who knows python better than I do could confirm that.


"You have a problem, so you think 'Hey, I'll just use a regex'. Now you have two problems"

Here's a much easier solution to your problem:

def shouldIignore(filename):
    ext = filename.split('.')[-1] # Get the extension
    ignorelist = ('.iso', '.pyc', '.blend1', '.bigfile')
    if ext in ignorelist:
        return True
    return False

And here's the added bonus - it should take all of 3 minutes? to extend this to get the extensions from an ignore file.

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消