English 中文(简体)
Ubuntu One Folder Sync Filter
原标题:

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 of 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

最佳回答

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 documentation for python would be the place to look that up.

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

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





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签