"""
Interface to the Sage fileserver
"""
import os
import subprocess
class FileServer(object):
def __init__(self):
self.user = 'sagemath'
self.hostname = 'fileserver.sagemath.org'
def upstream_directory(self, package):
"""
Return the directory where the tarball resides on the server
"""
return os.path.join(
'/', 'data', 'files', 'spkg', 'upstream', package.name,
)
def upload(self, package):
"""
Upload the current tarball of package
"""
if not package.tarball.is_distributable():
raise ValueError('Tarball of {} is marked as not distributable'.format(package))
subprocess.check_call([
'ssh', '[email protected]',
'mkdir -p {0} && touch {0}/index.html'.format(self.upstream_directory(package))
])
subprocess.check_call([
'rsync', '-av', '--checksum', '-e', 'ssh -l sagemath',
package.tarball.upstream_fqn,
'fileserver.sagemath.org:{0}'.format(self.upstream_directory(package))
])
def publish(self):
"""
Publish the files
"""
subprocess.check_call([
'ssh', '[email protected]', './publish-files.sh'
])