I use pysvn 1.7.5 to access my svn server.
If I want to copy a single file from a svn Server to my local disk there are no pysvn function implemented. But if I make a connection by https I can copy the single file, without doing a hole checkout on a directory.
def fetch_svn_file(self, file_url, local_path):
local_path = local_path.replace('\\', '/')
# Set up a HTTPS request with username/password authentication
try:
# create a password manager
password_mgr = HTTPPasswordMgrWithDefaultRealm()
# Add the username and password.
password_mgr.add_password(None, 'https://www.xyz.com', self.default_user, self.default_passwd)
opener = build_opener(HTTPBasicAuthHandler(password_mgr))
remote_file = opener.open(file_url)
content = remote_file.read()
try:
local_file = open(local_path,"w")
local_file.write(content)
local_file.close()
except IOError:
return -1
except URLError, e:
print 'URLError: "%s"' % e
return -2
return 0
The same way tortoise do it, if i drag a file from the Retro browser to my local disk, but tortoise can also copy single files in another revision. Anyone now how I can realise this in pysvn or in simple python code?? If these function is implemented by tortoise it has to be possible in pysvn too... because of the same developer team.
I already got the answer. :-)
there is a standart pysvn function called "pysvn.export". The name was so strange for a copy function....
Related
I'm trying to build a website that has one page for downloading some resources, and it just happened that my local flask version finds perfectly any file name (when using send_from_directory()), but once deployed at PythonAnywhere it just doesn't work for the filenames that have spanish accented characters such as á.
I guess it has something to do with unicode, but I couldn't find how to fix it (the logs at pythonanywhere don't seem to show anything, since flask simply delivers a "Not found" page to the user).
...and I'd really like to have those accents in the name of the files people download (they're anki decks, some of them intended for education purposes, and it just feels wrong to deliver bad ortography in the deck name).
My code looks like this:
#app.route('/anki/d/<file>')
def d_anki(file):
if file == "verbscat":
ankideck = "[Rusca] Temps Verbals Catalans.apkg"
elif file == "irregular":
ankideck = "[Rusca] Verbs Irregulars Anglès.apkg"
# ...
else:
return f"The file {file} wasn't found."
return send_from_directory("./static/anki/", ankideck, as_attachment=True, cache_timeout=0)
(then I link to this url in a button by <a href="/anki/d/irregular" ...>)
Oh I just realized I can choose a different name for the downloaded file by adding attachment_filename="Whatever I want to call it" to the parameters in send_from_directory.
So I guess we can do with this workaround (having the original files with simple non-accented names and adding the proper name afterwards).
if file == "irregular":
ankideck = "irregular.apkg"
name = "[Rusca] Verbs Irregulars Anglès.apkg"
# ...
return send_from_directory("./static/anki/", ankideck, as_attachment=True, attachment_filename=name cache_timeout=0)
I want to disable direct file download to my .zip files.
If my website is the referrer then only download the file.
I am using Apache server
You can try this one which will help you but I will suggest you to research more on this.However you can put the below code for the work.
Also make changes to the below code for the changes.
<?php
// This is to check if the request is coming from a specific domain domain.com
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
if($refData['host'] !== 'domain.com') {
// Output string and stop execution
die("Hotlinking not permitted");
}
echo "Executing code here";
?>
You need to change your domain above eg. clubapk.com instead of domain.com
Using Azure Logic apps, I have a requirement to poll a network file system folder for 3 files and my processing logic should start after receiving all 3 files in the file system.
I tried recurrence with List files in folder action and checking filenames one by one in a loop, but not working properly.
Is there a file poller trigger that checks a folder for file pattern match(Ex: abc*.csv, ghi*.csv) in Logic Apps?
Suggest how to implement this scenario.
Thanks,
Sunil
I test with the inline code with a test RegExp /^test.*.txt$/g, this check if the file start with test and end with .txt. The below is my code and I test with blob action.
var text = workflowContext.actions.Get_Blob_Metadata_using_path.outputs.body.DisplayName
var regexpattern=new RegExp(/^test.*.txt$/g);
return regexpattern.exec(text)[0]
If your file name match the regexp it will return the filename.
We use some Gradle base scripts on an central point. This scripts are included with "apply from:" from a large count of scripts. This base scripts need access to files relative to the script. How can I find the location of the base scripts?
Sample for one build.gradle:
apply from: "../../gradlebase/base1.gradle"
Sample for base1.gradle
println getScriptLocation()
I'm not sure if this is considered an internal interface, but DefaultScriptHandler has a getSourceFile() method, and the current instance is accessible via the buildscript property, so you can just use buildscript.sourceFile. It's a File instance pointing at the current script
I'm still not sure if I understood the question well but You can find path of current gradle script using following piece of code:
println project.buildscript.sourceFile
It gives the full path of the script that is currently running. Is that what You're looking for?
I'm pulling it off the stack.
buildscript {
def root = file('.').toString();
// We have to seek through, since groovy/gradle introduces
// a lot of abstraction that we see in the trace as extra frames.
// Fortunately, the first frame in the build dir is always going
// to be this script.
buildscript.metaClass.__script__ = file(
Thread.currentThread().stackTrace.find { ste ->
ste.fileName?.startsWith root
}.fileName
)
// later, still in buildscript
def libDir = "${buildscript.__script__.parent}/lib"
classpath files("${libDir}/custom-plugin.jar")
}
// This is important to do if you intend to use this path outside of
// buildscript{}, since everything else is pretty asynchronous, and
// they all share the buildscript object.
def __buildscripts__ = buildscript.__script__.parent;
Compact version for those who don't like clutter:
String r = file('.').toString();
buildscript.metaClass.__script__ = file(Thread.currentThread().stackTrace*.fileName?.find { it.startsWith r })
Another solution is set a property for the location of A.gradle in your global gradle settings at: {userhome}/.gradle/gradle.properties
My current workaround is to inject the path from the calling script. This is ugly hack.
The caller script must know where the base script is located. I save this path in a property before calling:
ext.scriptPath = '../../gradlebase'
apply from: "${scriptPath}/base1.gradle"
In base1.gradle I can also access the property ${scriptPath}
You could search for this scripts in the relative path like:
if(new File(rootDir,'../path/A.gradle').exists ()){
apply from: '../path/A.gradle'
}
This solution has not been tested with 'apply from', but has been tested with settings.gradle
Gradle has a Script.file(String path) function. I solved my problem by doing
def outDir = file("out")
def releaseDir = new File(outDir, "release")
And the 'out' directory is always next to the build.gradle in which this line is called.
How do I write a Google Apps Script that deletes files?
This finds files:
var ExistingFiles = DocsList.find(fileName);
But DocsList.deleteFile does not exist to delete a file.
Is there a way to move those files to another Folder or to Trash?
The other workaround I would consider is to be able to override an existing file with the same name.
Currently when I want to create a file with a name already used in MyDrive then it creates a second file with the same name. I would like to keep 1 file (the new one is kept and the old one is lost).
There are 3 services available to delete a file.
DriveApp - Built-in to Apps Script
Advanced Drive Service - Built-in to Apps Script but must be enabled. Has more capability than DriveApp
Google Drive API - Not built-in to Apps Script, but can be used from Apps Script using the Drive REST API together with UrlFetchApp.fetch(url,options)
The DocsList service is now deprecated.
The Advanced Drive Service can be used to delete a file without sending it to the trash. Seriously consider the risk of not being able to retrieve the deleted file. The Advanced Drive Service has a remove method which removes a file without sending it to the trash folder. Advanced services have many of the same capabilities as the API's, without needing to make an HTTPS GET or POST request, and not needing an OAuth library.
function delteFile(myFileName) {
var allFiles, idToDLET, myFolder, rtrnFromDLET, thisFile;
myFolder = DriveApp.getFolderById('Put_The_Folder_ID_Here');
allFiles = myFolder.getFilesByName(myFileName);
while (allFiles.hasNext()) {//If there is another element in the iterator
thisFile = allFiles.next();
idToDLET = thisFile.getId();
//Logger.log('idToDLET: ' + idToDLET);
rtrnFromDLET = Drive.Files.remove(idToDLET);
};
};
This combines the DriveApp service and the Drive API to delete the file without sending it to the trash. The Drive API method .remove(id) needs the file ID. If the file ID is not available, but the file name is, then the file can first be looked up by name, and then get the file ID.
In order to use DriveAPI, you need to add it through the Resources, Advanced Google Services menu. Set the Drive API to ON. AND make sure that the Drive API is turned on in your Google Cloud Platform. If it's not turned on in BOTH places, it won't be available.
Now you may use the following if the file is as a spreadsheet, doc etc.:
DriveApp.getFileById(spreadsheet.getId()).setTrashed(true);
or if you already have the file instead of a spreadsheet, doc etc. you may use:
file.setTrashed(true);
This code uses the DocsList Class which is now deprecated.
try this :
function test(){
deleteDocByName('Name-of-the-file-to-delete')
}
function deleteDocByName(fileName){
var docs=DocsList.find(fileName)
for(n=0;n<docs.length;++n){
if(docs[n].getName() == fileName){
var ID = docs[n].getId()
DocsList.getFileById(ID).setTrashed(true)
}
}
}
since you can have many docs with the same name I used a for loop to get all the docs in the array of documents and delete them one by one if necessary.
I used a function with the filename as parameter to simplify its use in a script, use test function to try it.
Note : be aware that all files with this name will be trashed (and recoverable ;-)
About the last part of your question about keeping the most recent and deleting the old one, it would be doable (by reading the last accessed date & time) but I think it is a better idea to delete the old file before creating a new one with the same name... far more logical and safe !
Though the The service DocsList is now deprecated, as from the Class Folder references, the settrashed method is still valid:
https://developers.google.com/apps-script/reference/drive/folder#settrashedtrashed
So should work simply this:
ExistingFiles.settrashed(true);
Here is another way to do it without the need of Drive API. (based on Allan response).
function deleteFile(fileName, folderName) {
var myFolder, allFiles, file;
myFolder = DriveApp.getFoldersByName(folderName).next();
allFiles = myFolder.getFilesByName(fileName);
while (allFiles.hasNext()) {
file = allFiles.next();
file.getParents().next().removeFile(file);
}
}
Here is a slightly modified version using the above. This will backup said file to specified folder, also remove any old previous backups with the same name so there are no duplicates.
The idea is here to backup once per day, and will retain 1 month of backups in your backup folder of choice. Remember to set your trigger to daily in your Apps Script.
https://gist.github.com/fmarais/a962a8b54ce3f53f0ed57100112b453c
function archiveCopy() {
var file = DriveApp.getFileById("original_file_id_to_backup");
var destination = DriveApp.getFolderById("backup_folder_name");
var timeZone = Session.getScriptTimeZone();
var formattedDate = Utilities.formatDate(new Date(),timeZone,"dd"); // 1 month backup, one per day
var name = SpreadsheetApp.getActiveSpreadsheet().getName()+"_"+formattedDate;
// remove old backup
var allFiles = destination.getFilesByName(name);
while (allFiles.hasNext()) {
var thisFile = allFiles.next();
thisFile.setTrashed(true);
};
// make new backup
file.makeCopy(name,destination);
}